RegEx: question mark

Posting here is no longer possible, please use the forum of a filter list project, such as EasyList
Locked
User avatar
Parson
Posts: 65
Joined: Fri Jun 16, 2006 10:32 am
Location: Germany, Beach District

RegEx: question mark

Post 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"?
User avatar
mcm
Posts: 359
Joined: Sat Jun 10, 2006 2:36 am

Post 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)/
User avatar
Parson
Posts: 65
Joined: Fri Jun 16, 2006 10:32 am
Location: Germany, Beach District

Post by Parson »

Ah, I see. Thanks for the help.
Locked