Comment on Regex tutorial for people who should know Regex, but do not.. Part 2

scott.wimer@gmail.com
Tue, 19 Feb 2008 04:14:55 +0000

Thank you for putting the time and effort into this introduction. I think it will help quite a few people that might not otherwise feel comfortable with regular expressions.

A typo: When you introduce spaces to your character class example "[a-zA-Z0-9-_ ]+", the '-' needs to either be the last member of the character class, or slash escaped. Otherwise, you're telling most regex parsers (Perl, Python, PCRE, and probably any others that matter) that the character class matches the range from 9 to _ in ASCII. That's likely to not be what you want.

The regex for the intended character class could be: [a-zA-Z0-9_ -]+ or [a-zA-Z0-9-_ ]+