Welcome to WebmasterWorld Guest from 54.159.250.110

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Long time no posting! I've a regex question!

   
11:47 am on Mar 2, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



HI there people,

Crikey, feels like ages since i've posted on here, hope as everyone is having a good time :)

Business:

Simple regex:

^[A-Z]/[A-Z]{2}[0-9]{3}/[0-9]{2}$

This checks for - AP/PD123/13, how can I change this to add an either or type operator in there, sort of like this:-

^[A-Z]/[A-Z]{2}[0-9]{3}/[0-9]({2}|{3})$

I'm sure that this is correct, but it's not reacting to the change.

?

Thanks in advance.

Cheers,
MRb
2:22 pm on Mar 2, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Beginning
^[A-Z]/
it does NOT match two letters, only one.

"two or three digits" is done with
[0-9]{2,3}


Welcome back!
2:50 pm on Mar 2, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there g1smd,

Sorry, that was down to sloppy copy n pasting!

Thanks for the solution there too, I'm not brilliant at doing regex & I thought as the | would work like it does in C. There I go assuming again lol!

Thanks for the welcome back there too.

Cheers,
MRb
3:24 pm on Mar 2, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



/([0-9]{2}|[0-9]{3})$

would work, but the general rule is "when something repeats, stuff can be combined", hence
/[0-9]{2,3}$
instead.
10:12 pm on Mar 2, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi g1smd,

I've just tested it, and it works great; I opted for the 'short-hand' version, and I've now combind an array of possible combinations down to 4 opposed to 8.

Thanks for the help once again!

Cheers,
MRb
12:40 am on Mar 3, 2013 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



There was a longer thread about combining things only yesterday or the day before.

Might be some extra clues in there too!