Forum Moderators: open

Message Too Old, No Replies

Reg Expressions

         

aspdaddy

9:56 am on Jul 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi What is the reglar expression for this:

LNNNN-?N

where
l=letter
n=number 1-9
- = -
?= Number 0 or 'E'

e.g
A1978-01
C1351-04
G1978-E2
G1851-E2
S0142-01

Thanks!

coopster

3:28 pm on Jul 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



[a-zA-Z][1-9][1-9][1-9][1-9]-(0¦E)[1-9]

However, I noticed your last example there contains a zero in the second position which is contrary to your definition of "N" being a number between 1 and 9. If you want it to include zeros, replace every occurrence of "1" in the regular express with a "0".

Don't forget that the forum breaks the pipe character, you need to key it again if you copy/paste

aspdaddy

4:30 pm on Jul 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that. :)

coopster

9:19 pm on Jul 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure. You might want to anchor those as well, to make sure they begin and end with that exact pattern.

^[a-zA-Z][1-9][1-9][1-9][1-9]-(0¦E)[1-9]$

mrMister

9:12 am on Jul 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming you mean 0-9 and not 1-9, use this...

^[a-zA-Z]\d{4}-(0¦E)\d$

If you did mean 1-9 then use this...

^[a-zA-Z][1-9]{4}-(0¦E)[1-9]$

As a rule of thumb, shorter regular expressions tend to be more efficient.

[edited by: mrMister at 9:16 am (utc) on July 19, 2006]

aspdaddy

1:45 pm on Jul 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks people, got it.

oRegExp.Pattern = "(^[a-zA-Z][1-9]{4}-[0¦E][1-9]$)"

For some reason my version of IIS requires square brackets round the 0¦E and round brackets around the whole thing to work properly.