View Single Post
 01-17-2013, 09:51 PM PM User | #7 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,955 Thanks: 75 Thanked 4,308 Times in 4,275 Posts Each *group* of characters in [...] is treated as "choose one of these". So when you did [a-z][A-Z] that said "choose a lower case letter" and then "choose an upper case letter". But then you actually used [A-Z]{0,1} which means "choose that expression [in this case upper case letter] from 0 to 1 times. {a,b} means "repeat from a through b times". {0,1} is equivalent to just ? -- as in [A-Z]? {1,} is equivalent to just + -- as in [A-Z]+ {0,} is equivalent to just * -- as in [A-Z]* Anyway, you then grouped all that: ([a-z][A-Z]{0,1}) -- lower case letter followed by 0 through 1 upper case letters and added the + ([a-z][A-Z]{0,1})+ and as I just said, the + is equivalent to {1,} which means 1 through ANY NUMBER of occurrences So ([a-z][A-Z]{0,1})+ means "lower case letter followed by optional upper case letter and the whole thing repeated one or more times" aaaaaaaaaaaaaaaBaBaBaBaBaaaaaaaaaaa would fit that pattern, just for example. You then did \d{1,8} which means (as above) "any digit, repeated 1 through 8 times." SO 7 7131 871122 81712290 would all match that. But then the big mistake you made was in omitting the \$ at the end. Without that, your expression places NO LIMIT on what can follow the REQUIRED part!!! ********* Not all features of regular expressions are standard across all languages. For example, I have seen some where \d is not recognized as being the same as [0-9]. But most features are the same, including the use of ( ) for grouping, [...] for character choices, ^ and \$ for beginning/ending of text matches, and {...} for repetition counts. I don't think I 've seen any language that doesn't support all those. MySQL has some really funky requirements, just to pick the one oddball I am most familiar with. But it only takes a couple of minutes looking at their docs to get them right. __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
 Users who have thanked Old Pedant for this post: alykins (01-18-2013)