anyone have a regex to return a substring preceding or following the first occurrence of a delimiter?
DetlevD
Sep 9 2008, 05:12
QUOTE (egd @ Sep 9 2008, 00:53)

anyone have a regex to return a substring preceding or following the first occurrence of a delimiter?
Any example?
What delimiter?
DD.20080909.0611.CEST
hello : world
hello:world
hello: world
hello :world
In each case I would love regex's to return "hello" or "world", depending on requirements. The delimiter could be something else also, but let's assume it could be any of ":;,"
DetlevD
Sep 9 2008, 13:08
$regexp('hello : world',^(.+?) *'[:;,]+' *(.+?)$,$1) ==> 'hello'
$regexp('hello : world',^(.+?) *'[:;,]+' *(.+?)$,$2) ==> 'world'
$regexp('hello:world',^(.+?) *'[:;,]+' *(.+?)$,$1) ==> 'hello'
$regexp('hello:world',^(.+?) *'[:;,]+' *(.+?)$,$2) ==> 'world'
$regexp('hello :world',^(.+?) *'[:;,]+' *(.+?)$,$1) ==> 'hello'
$regexp('hello :world',^(.+?) *'[:;,]+' *(.+?)$,$2) ==> 'world'
$regexp('hello: world',^(.+?) *'[:;,]+' *(.+?)$,$1) ==> 'hello'
$regexp('hello: world',^(.+?) *'[:;,]+' *(.+?)$,$2) ==> 'world'
DD.20080909.1408.CEST
thank you. Forgive my ignorance, but what would the "Regular expression" and "Replace matches with" entries look like if this were turned into an action?
DetlevD
Sep 10 2008, 06:11
QUOTE (egd @ Sep 9 2008, 22:34)

thank you. Forgive my ignorance, but what would the "Regular expression" and "Replace matches with" entries look like if this were turned into an action?
I leave this task to you: transferring of these $regexp() expressions into Mp3tag action forms.
You may have to check the case when there is no match at all (if there is no delimiter).
DD.20080910.0710.CEST
QUOTE (DetlevD @ Sep 10 2008, 15:11)

I leave this task to you: transferring of these $regexp() expressions into Mp3tag action forms.
You may have to check the case when there is no match at all (if there is no delimiter).
DD.20080910.0710.CEST
I'd tried it and got no result, hence my asking. What I did was as follows:
For $regexp('hello : world',^(.+?) *'[:;,]+' *(.+?)$,$1) ==> 'hello'
Regular expression: ^(.+?) *'[:;,]+'
Replace matches with: *(.+?)$,$1)
DetlevD
Sep 10 2008, 08:07
QUOTE (egd @ Sep 10 2008, 07:37)

I'd tried it and got no result, hence my asking. ...
Look at
http://help.mp3tag.de/en/main_scripting.htmlQUOTE
$regexp(what,expr,repl)
Replaces the pattern specified by the regular expression expr in the string what by repl. The fourth optional parameter enables ignore case (1) or disables the ignore case setting (0). Please note that you have to escape comma and other special characters in expr (see end of this document).
$regexp(
'hello : world',
^(.+?) *'[:;,]+' *(.+?)$,
$1)
DD.20080910.0907.CEST
QUOTE (DetlevD @ Sep 10 2008, 17:07)

Look at
http://help.mp3tag.de/en/main_scripting.html $regexp(
'hello : world',
^(.+?) *'[:;,]+' *(.+?)$,
$1)
DD.20080910.0907.CEST
Hi DetlevD
Thanks for getting back to me. I've tried the above at
http://www.regextester.com/ using:
regex: ^(.+?) *'[;]+' *(.+?)$
Test on Text: hello : world
Replace with: $1
and it returns "No match"
I've gotten it working

seems one has to to remove the "
'" on either side of
'[:;,]+
' for the expression to evaluate.
thanks again
DetlevD
Sep 10 2008, 15:52
QUOTE (egd @ Sep 10 2008, 15:21)

I've gotten it working

I'm glad to hear this!
QUOTE (egd @ Sep 10 2008, 15:21)

... seems one has to to remove the "'" on either side of '[:;,]+' for the expression to evaluate. ...
Ah, yes, the single quotation mark
' is used within the $regexp() function as an escape character to prevent such special characters like e. g. square brackets or commas from misinterpreting by the function parameter parser.
The Mp3tag regex action form does not need this extra escaping.
DD.20080910.1652.CEST