RSS Forums RSS
Please support our C# advertiser: Programming Forums

Regular Expressions

Join Date: Jun 2005
Location: Seattle, WA
Posts: 53
Reputation: senexom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
senexom's Avatar
senexom senexom is offline Offline
Junior Poster in Training

Re: Regular Expressions

  #2  
Jul 26th, 2005
k... I'm not a RexEx guru either but I'm going to give it a shot, bolded blue text text will be subject of my explanation when regex expressions are used...

your expression [1-9]|1[0-5]

Scenario A: [1-9]|1[0-5] means match any number 1 thru 9, pretty basic
[1-9]|1[0-5] is a logical operator [OR]
Scenario B:[1-9]|1[0-5] means any number zero thru five

ok now that we broke it down lets look at what your expression would match...
1 = match based on scenario A
2 = match basesed on A
... up to 9 would match!
10 = now comes the fun part the 1 would match Scenario A and since there was a match it doesnt evaluate it under scenario B and 0 gets ignored.
11 = again Scenario A twice and doesn't even get to scenario B

so for it two work you must have it backwards
1[0-5]|[1-9]

and I would even go a step further and make sure the match is not in the middle of a string by adding ^ in the begging of the expression to indicate begining of line or a word and $ at the end of the expression to indicated end of line or word, like so...
(^1[0-5]$)|(^[1-9]$)

I hope this helps.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:55 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC