One RegEx not working

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Thany
Senior Member
Senior Member
Posts: 293
Joined: 2003-09-30, 09:20 UTC
Location: Netherlands

One RegEx not working

Post by *Thany »

I just noticed a bug in the regular expression engine. Consider the following regex:

Code: Select all

[0-9]{,4}(\([0-9]\))?\.jpg
This one should return files beginning with at most 4 digits, following by an optional digit between brackets. And it has the jpg extension. And guess what: it doesn't work :)

Only when I replace the {,4} part with {0,4} it works. But AFAIK this is a valid regex...
User avatar
fnheiden
Senior Member
Senior Member
Posts: 234
Joined: 2003-02-16, 12:06 UTC
Location: Dresden, Germany
Contact:

Post by *fnheiden »

Form TC help file section 3n:
{n} exactly n occurances
{n,} at least n occurances
{n,m} at least n and max. m occurances
~ Florian
Thany
Senior Member
Senior Member
Posts: 293
Joined: 2003-09-30, 09:20 UTC
Location: Netherlands

Post by *Thany »

So, this ain't not a bug-report, but a feature-request ;)
User avatar
JackFoo
Senior Member
Senior Member
Posts: 373
Joined: 2003-02-05, 19:53 UTC
Location: ERROR

Post by *JackFoo »

Thany wrote:This one should return files beginning with at most 4 digits, following by an optional digit between brackets. And it has the jpg extension.
You should also take into account that it'll return files like
asdf(10).jpg
fff.jpg
actually it'll return any .jpg file (unless I'm missing something and I don't thinks that I do). So you could safely not use regex.

* For more strict rules look at ^ and $.

EX: this is inherent of the way RegEx's function, when you specify [0-9]{0,4}(\([0-9]\))? it means "it can have" this before .jpg but this doesn't say a lot it's like saying it can have anything before .jpg, for instance it also matches 11111(0).jpg which has 5 digits before (0) and this happens because (0) also has 4 digits before (0). For some help on solving look at *.
Thany
Senior Member
Senior Member
Posts: 293
Joined: 2003-09-30, 09:20 UTC
Location: Netherlands

Post by *Thany »

Thanks for the info, I was thinking the regular expression always had to match the whole filename, but I guess not. So to match the whole filename, I obviously put ^and $ around the expression.

BTW, I always globally check by hand if the search returned what I wanted, so it's not really a big deal if it returns more than I want...
User avatar
Hacker
Moderator
Moderator
Posts: 13142
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

I was thinking the regular expression always had to match the whole filename, but I guess not.
Yeah, as I first saw it I thought so, too, so/but now it's in the Help:
Note: This finds "test" ANYWHERE in a file name or on a line in text.
:)

Roman
Post Reply