js re bs

From: Peter (BOUGHTONP)22 Apr 2012 19:29
To: CHYRON (DSMITHHFX) 3 of 4
If you don't wrap your pattern in parentheses, you wont be unnecessarily capturing the content into group 1, and thus wont get two items in your array.

(You only need a capturing group when you need part of an expression, because the whole match is always captured.)

As Matt points out, just grabbing any sequence of numerical digital is possibly not specific enough.

However, I would probably do it this way instead:

javascript code:
var thepage = /\d+(?=\.htm)/i.exec(window.location.href);


And then you can either access thepage[0], or let it be converted to a string, and you'll have the number you want, only once.
EDITED: 22 Apr 2012 19:31 by BOUGHTONP
From: CHYRON (DSMITHHFX)22 Apr 2012 20:22
To: Peter (BOUGHTONP) 4 of 4

That works perfectly. Thanks!

 

Matt: fwiw (apparently not much), there are no other numbers in the url. That's probably the first javascript re I tried to write from scratch, as opposed to plagiarize + hack.