Forum Moderators: open

Message Too Old, No Replies

Regex Help

         

aspdaddy

3:05 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do I make this regex so that it allows the end to be just -E , like A1234-E butif a number is used it needs two digits so that it doesnt allow A1234-0 but allows A1234-01

(^[A-Z]\d{4}-[0¦E][0-9]?)

Thanks.

cmarshall

3:33 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How do I make this regex so that it allows the end to be just -E , like A1234-E butif a number is used it needs two digits so that it doesnt allow A1234-0 but allows A1234-01

(^[A-Z]\d{4}-[0¦E][0-9]?)

Thanks.

Well, according to this tool [my-tool.com], you would need it to be:

/^[A-Za-z0-9]+-(\d\d¦[A-Za-z]{1})$/

aspdaddy

6:55 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That doesnt really do it. What I need is something like this for the start:

^[A-Z]\d{4}-

Then either of these 3 endings:
[0][1-6]
[E][1-3]
[E]

A1234-01,A1234-E1 & A1234-E are all valid.
A1234-0,A1234-1 are invalid.

Any ideas?

cmarshall

7:25 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/^[A-Z][0-9]{4}\-([0-9][0-9]¦[E][1-6]?¦[O][1-3]?)$/

CAVEAT: This works in the PHP style. Your mileage may vary.

aspdaddy

1:07 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, got there in the end :)

oRegExp.Pattern = "(^[A-Z]\d{4}-[E]¦[0][1-6]¦[E][[1-3])"

cmarshall

1:23 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great! I see I had some dyslexia.

Looks like that will work fine.

Isn't RegEx FUN?