Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
nwp
Forum Contributor
Posts: 105 Joined: Sun Feb 04, 2007 12:25 pm
Post
by nwp » Sat Feb 17, 2007 12:05 am
I need a regex pattern to match "2B84-5UD-80T7"
i.e. 4 hexadecimals separated by "-" the length of each part (Separated by -) can be 1, 2, 3, .........................
I've tried the following
But it did not work.
would anyone please make one for me ??
EDIT
Small caps alphabets are not allowed also thats only A-Z no a-z
GeertDD
Forum Contributor
Posts: 274 Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium
Post
by GeertDD » Sat Feb 17, 2007 2:17 am
Code: Select all
/^([0-9A-Z]+)-([0-9A-Z]+)-([0-9A-Z]+)$/
Edit:
Hmm, I'd love to simplify this regex using backreferences within the pattern, but PCRE doesn't seem to support this..?
nwp
Forum Contributor
Posts: 105 Joined: Sun Feb 04, 2007 12:25 pm
Post
by nwp » Sat Feb 17, 2007 3:31 am
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Feb 17, 2007 8:27 am
GeertDD wrote: Edit:
Hmm, I'd love to simplify this regex using backreferences within the pattern, but PCRE doesn't seem to support this..?
Yes, it does. However it does not use the pattern referenced. It uses the matched text.
Side note: the characters aren't hexadecimal.
GeertDD
Forum Contributor
Posts: 274 Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium
Post
by GeertDD » Sat Feb 17, 2007 9:12 am
Thanks for the clarification, feyd. Now I understand.
Had never really used backreferences within a pattern before and this seemed like a good situation to test them -- not.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Sat Feb 17, 2007 9:48 am
Hmm, that doesn't look like hexadecimal to me.... [0-9A-F] would be hexadecimal.
GeertDD
Forum Contributor
Posts: 274 Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium
Post
by GeertDD » Sun Feb 18, 2007 10:17 am
d11wtq wrote: Hmm, that doesn't look like hexadecimal to me.... [0-9A-F] would be hexadecimal.
Right, but if nwp needs to match "2B84-5UD-80T7", you need more than hexadecimal characters alone. I guess he'll be able to figure it out now.