Regex – Should hyphens be escaped? [duplicate]

Possible Duplicate:
How to match hyphens with Regular Expression?

Hyphen is a special character in regex, for instance, to select a range, I could do something like:

[0-9A-F]

But outside of square brackets it’s just a regular character right? I’ve tested this on a couple of online regex testers, and hyphens seem to function as a normal character outside of square brackets (or even inside of square brackets if it’s not in-between two characters – eg [-g] seems to match – or g) whether it’s escaped or not. I couldn’t find the answer to this, but I’m wondering whether or not it is conventional to escape hyphens.

Thanks!

3 Answers
3

Leave a Comment