mIRC Home    About    Download    Register    News    Help

Print Thread
validation check #185903 15/09/07 08:41 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
-

Re: validation check using regex [Re: pouncer] #185904 15/09/07 08:55 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
/^([A-Z][a-z]{2}) (?1) \d{4} (\d{4}:)(?2)\d{4} PMD-\d{4} 9999$/

Re: validation check using regex [Re: hixxy] #185905 15/09/07 09:08 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks alot hixxy, it is perfect!!!

can i ask what the (?1) and (?2) do?

Re: validation check using regex [Re: pouncer] #185907 15/09/07 09:16 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
When you put a pattern inside brackets, the regex engine will remember the match in case you want to use it again later, so if you used the regex:

Code:
/^([A-Z])([a-z]{4})$/


On the string:

Code:
Zebra


Then \1 would refer to the letter "Z", because it is the first match you made, and \2 would be "ebra", because it's the second. (?N) differs from \N because it remembers the pattern, not the result. So ([A-Z][a-z]{4})(?1) would be a shorthand way of writing ([A-Z][a-z]{4})(?:[A-Z][a-z]{4})

Or in the case of the first example, (?1) would be [A-Z] and (?2) would be [a-z]{4}

Re: validation check using regex [Re: hixxy] #185930 16/09/07 06:32 AM
Joined: Jul 2006
Posts: 107
L
LonDart Offline
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
I really appreciate your regex skills and your explanation.

But this is driving me crazy....
How the heck did you know what he wanted?!

The entire text of the original post consists of a hyphen.

(I am soooo lost.)


LonDart
Re: validation check using regex [Re: LonDart] #185931 16/09/07 06:36 AM
Joined: Dec 2002
Posts: 3,138
C
Collective Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
He edited his post after making it, it was originally regarding matching registration keys for some program or other.

Re: validation check using regex [Re: Collective] #185932 16/09/07 07:01 AM
Joined: Jul 2006
Posts: 107
L
LonDart Offline
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
Ah ok. Thanks. Thought I was losing my mind smile

I'd looked for an 'edited' notation on that post. Apparently that is optional.


LonDart