Codingjs re bs

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  CHYRON (DSMITHHFX)      
39501.3 In reply to 39501.1 
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.
0/0
 Reply   Quote More 

 From:  CHYRON (DSMITHHFX)   
 To:  Peter (BOUGHTONP)     
39501.4 In reply to 39501.3 

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.


----
"Russian City Ever Watchful Against Being Sucked Into Earth"
0/0
 Reply   Quote More 

Reply to All    
 

1–4

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats