Need help with RegExp


#1
$regexp('123','^(.)',) ==> '23' $regexp('123','^(.)','$1') ==> '123' $regexp('123','^(.)','$2') ==> '23'


Please, could someone explain these RegExp results.
Thank you in advance.

DD.20110128.1248.CET


#2

Hmmm... there's something odd about this.

The caret (^) indicates the beginning of a string. So '^ means: an apostrophe followed by the beginning of a string, which is a match impossible in any case. So the Reg Ex should match nothing. Yet apparently it matches "1". I'm guessing this has to do with the fact that the apostrophe (') is used to escape characters inside the MP3Tag scripting language. Maybe try using two apostrophes ('') if you want to match a single one.


#3

Come on Detlev, you?

The first character is repalced by nothing = '1' get deleted

The first character gets replaced by itself. $1 is what is inside the parenthesis = the first character.

The first character gets replaced by what is inside the second parenthesis. As there is no second parenthesis, it gets replaced by nothing.

In all three cases just the first character gets replaced, '23' is not included in the regular expression and keeps unchanged.

Glad to help you.

EDIT:
Why do you always use this apostrophes in your regexps? They are not needed.


Reg ex problem, please help.
#4

Yes, sometimes it hits me too ;-).

Hmm, yes, these apostrophes are not needed, in most cases, but neglecting them is only possible due to too loose and partly unsystematic syntax of the Mp3tag scripting language.

Because I "think", that the first three parameters of the function Regexp() should be of type string (if Mp3tag scripting language would know about a datatype string), the fourth parameter is a simple integer, if not of type boolean, and ...
because the enclosing of the parameter expressions by apostrophes will auto-devalue resp. auto-escape all specific trap characters like square brackets and others, ...
so it has become a habit to make sure to write safe regular expressions by the easy way of 'escape always' regexp() parameters.

There is one argument more ... the scripting syntax colorizer I use want to know what part of the Mp3tag scripting language is a string and what are other scripting elements.
And my eyes want this too.
Writing script code with Mp3tag scripting language while reading colorized code is a good thing.
See also:
http://cid-387b58366897ac93.office.live.co...%20Highlighting

So back to the problem - is there any problem yet?
Now there is no more, but thought there have been one or two.

Example 1 was clear to me.
Take the first char of the string '123' and eliminate it. The remainder will be '23'.

Example 2 was not so clear to me.
Because I was on the "do what I mean way" I did expect to extract only the bracketed char, but forgot the other remaining chars, which will be shown unhandled by the regular expression.
If I would have coded the test case like following, it would have been obvious to me.

$regexp('123','^(.)','-$1-') ==> '-1-23'

Example 3 let me think something I want not to repeat here.
If I would have coded the test case like following, it would have been obvious to me.

$regexp('123','^(.)','-$2-') ==> '--23'

Yes, indeed.

Thank you pone for helping me to open my eyes and to remove my brain blockage.

DD.20110128.2057.CET


#5

Because the apostrophe has the meaning of a string delimiter in the Mp3tag scripting language, a sequence of chars enclosed in apostrophes is just a sequence of chars, with the advantage that all characters will be used as literals. The meanings of special characters are devalued.

Mp3tag first parses it's own language, then the Regexp language, so that the apostrophes will not occur as part of the parameter in the Regexp function.

Thank you for your involvement with the subject.

DD.20110128.2110.CET