Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster

For anyone who is having trouble with regular expressions, I suggest you have a look at this site by Jeff Avallone. It takes a regular expression in the native (cryptic) format and produces a visual display of the same expression. For example,

^[a-z0-9_-]{3,16}$

becomes

Screenshot_(10).png

and the pattern for an email address

^([a-z0-9_.-]+)@([\da-z.-]+).([a-z.]{2,6})$

becomes

Screenshot_(11).png

One caveat - you will see

\d{3,5}

expanded as

Screenshot_(12).png

which may seem incorrect at first glance, however, the 2...4 times refers not to the number of digits but the number of extra "trips" back through the loop so if you have three digits you require two extra trips back through. I recently suggested to the author that he consider labelling the iterators something like 3...5 occurrences which would be both clear and precise.

In any case, this is a valuable tool for debugging complex expressions.

rproffitt commented: 2..4 times or more useful. Molsen OK by you? +12
JamesCherrill commented: Wow - that's really useful. Thanks +15
cereal commented: thank you! +14
ddanbe commented: Great tip! Thanks :) +15
Nutster commented: Good link and explanation, but the Email address pattern needs to escape the period between groups 2 and 3. +7