Complex(?) regex: Is expression, but not another

Posted by Kieron on Stack Overflow See other posts from Stack Overflow or by Kieron
Published on 2010-06-12T17:39:04Z Indexed on 2010/06/12 17:42 UTC
Read the original article Hit count: 806

Filed under:
|

(If you can make a better title, please do)

Hi,

I need to make sure a string matches the following regex:

^[0-9a-zA-Z]{1}[0-9a-zA-Z\.\-_]*$
(Starts with a letter or number, then any number of letters, numbers, dots, dashes or underscores)

But given that, I need to make sure it doesn't match a Guid, my Guid matching reg-ex looks like this (obviously, this needs to be negated in the merged result):

^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$

The last requirement here is that they must (if it's possible) be merged into a single expression.

© Stack Overflow or respective owner

Related posts about regex

Related posts about regex-negation