[X] $regexp(X,.*$,YY) ...


#1

[EDITED:] ... returns YYYY rather than YY as documented.


#2

The regular expression from the topic return YYYY because .* matches nothing and the X.

This is no bug and works as intended.


#3

The regular expression from the topic return YYYY

(Agreed - my typo, sorry. Original report now corrected.)

.* matches nothing and the X.

Indeed, as proved by $regexp(X,(.*)$,(\1)) -> (X)()

I have used regexp in dozens of other tools and languages, and never seen a single wild card expression generate TWO SEPERATE replacement expressions.

This is no bug

It is a failure to accord with the docs - * is supposed to be greedy i.e. match everything in one hit.

Are the docs in error, then?


#4

No, I don't think so.


#5

"*" repeated any number of times including zero

That doesn't mean it isn't by default greedy. But

Non-greedy repeats
Non-greedy repeats are possible by appending a '?' after the repeat;
a non-greedy repeat is one which will match the shortest possible string.

surely does.

What's your understanding Florian? Is * (without ?) supposed to be greedy, or, not?


#6

Sure, that's why there is an extra specifier to turn of greedyness.


#7

Is * (without ?) supposed to be greedy, or, not?
Sure, that's why there is an extra specifier to turn of greedyness.

I take that to mean "Sure, it is supposed to be greedy".

Well, Florian, then it is not working properly.

When .* is greedy, $regexp(X,.$,YY) gives YY because greedy . matches the entire input string, and that is replaced by a single occurence of the replacement string YY. This is indeed what I get on the other regexp implemetations I just tested.

But on Mp3tag, $regexp(X,.*$,YY) gives YYYY.

that's why there is an extra specifier to turn of greedyness.

Actually that doesn't work either, but let's deal with one issue at a time.

PS Here's a quote from http://en.wikipedia.org/wiki/Regular_expressions#Syntax which whilst not necessarily being a spec Mp3tag aims to comply with, does define what's generally meant by 'greedy':

. The standard quantifiers in regular expressions are greedy, meaning
. they match as much as they can, only giving back as necessary to
. match the remainder of the regex.