Page 1 of 1

RegEx: question mark

Posted: Tue May 30, 2006 7:33 am
by Parson
With this simplest RegEx-filter

Code: Select all

/\/ad?[0-9]\.(gif|jpg|png)/
I'd like to catch images called ad1.gif or ad4.png. This works but I wonder why it doesn't match when the filename doesn't contain the number: ad.gif slips through.

Why that? I thought the question mark means "one or zero"?

Posted: Wed May 31, 2006 3:13 am
by mcm
Yes it does but it works on the preceding character which in this case is 'd' so 'a1.gif' or 'a4.gif' currently match as well. The filter should really be:

Code: Select all

/\/ad[0-9]?\.(gif|jpg|png)/

Posted: Wed May 31, 2006 6:50 am
by Parson
Ah, I see. Thanks for the help.