...

View Full Version : Is there any difference between these RegEx patterns?



swmr
01-03-2004, 08:34 AM
I'd like to validate input of a classid - registry key value:
"{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" -- where "x" is a hex-digit.

pattern-1:

/{{1}[0-9A-F]{8}-{1}[0-9A-F]{4}-{1}[0-9A-F]{4}-{1}[0-9A-F]{4}-{1}[0-9A-F]{12}}{1}/i

pattern-2:

/{{1}[\dA-F]{8}-{1}[\dA-F]{4}-{1}[\dA-F]{4}-{1}[\dA-F]{4}-{1}[\dA-F]{12}}{1}/i

pattern-3:

/{{1}[0-F]{8}-{1}[0-F]{4}-{1}[0-F]{4}-{1}[0-F]{4}-{1}[0-F]{12}}{1}/i

- just want to know if the shortest one is best... or if this can be further condensed.

<edit>fixed a mistake in the last one :rolleyes: </edit>

brothercake
01-03-2004, 12:02 PM
Can you go [0-F] ? I think that has to be [0-9A-F].

Those {1} are certainly unecessary, and you could probably loop the middle bit if ([blah]{n}){n} is allowed .. so:


/{[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}}/i

i'm typing off the top of my head here .. haven't tested it ..

swmr
01-03-2004, 12:34 PM
Hey now, that seems to work... & much shorter too! :thumbsup:

- didn't expect the [0-F] to fly, but I can't make it miss either... are there any characters between [0-9] & [A-F] that could sneak in there?

brothercake
01-03-2004, 12:37 PM
in a classid? I'm not sure ... don't think so

swmr
01-05-2004, 06:30 AM
ah, I found the ASCII range: [0123456789:;<=>?@ABCDEF]...

so, [0-F] would allow these non-hex characters to validate [: ; < = > ? @]

oops :D

brothercake
01-05-2004, 11:11 PM
Oh right .. I didn't realise you can span whole ASCII ranges, I though it was in discrete sets of numbers and letters.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum