Henry Wong wrote:The second regex will reluctantly match one or more whitespace characters. For most purposes, these two regexes are very similar, except in the second case, the regex can match more of the string, if it prevents the regex match from failing.
Good old regex, eh? Powerful, beautiful, and totally arcane to all but the few thousand that like it (or, like me, as a Sysadmin, had it thrust on them).
@Martin: That 'reluctant' qualifier (?) is worth knowing about because, by default, regex
patterns are "greedy" (that is, they will match the
largest pattern they can find). Unfortunately, it's
also used to mean "0 or 1", so you need to be careful when you're interpreting them.
And just in case it comes up: regexes are powerful, but
not omnipotent; and one particular thing they are NOT suited for is parsing tagged input like HTML/XML. If you ever find yourself needing to do it, use a proper SAX or DOM-based parser.
Winston