SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: RegEx Number Ranges
-
Jul 9, 2008, 01:50 #1
- Join Date
- Jul 2008
- Location
- Somerset, England
- Posts
- 459
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
RegEx Number Ranges
Hi everyone!
I am trying to lnclude the number ranges 1 through 15 in a regular expression I am writing for my website.
I have been doing some reading on number ranges but I cant quite work it out, any help would be much appreciated!
kind regards,
John
-
Jul 9, 2008, 04:36 #2
- Join Date
- Apr 2006
- Posts
- 802
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If the value is the entire string use test-
if(/^(1[0-5]|[1-9])$/.test(str);
If you are seaching through a long string for possible multiple instances of the pattern use exec:
Code:var Rx=/(^|\D)(1[0-5]|[1-9])(\D|$)/g; var str='There are 14 days in 2 weeks and 21 days in 3 weeks'; var M, A=[]; while((M=Rx.exec(str))!=null){ A.push(M[2]); } alert(A);// return A or handle any processing in the loop
-
Jul 9, 2008, 04:45 #3
- Join Date
- Jul 2008
- Location
- Somerset, England
- Posts
- 459
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I really cant thankyou enough MrHoo !!!
very kind of you to help.
kind regards
-
Jul 9, 2008, 05:34 #4
- Join Date
- Jul 2008
- Location
- Somerset, England
- Posts
- 459
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi again!
That solution worked great!Last edited by johnuk; Jul 16, 2008 at 05:20.
Bookmarks