Please take a minute to check our Frequently Asked Questions. Use Search to reveal possible related topics.
Also make sure you've read the Forum Guidelines before posting in this forum.
![]() ![]() |
Sep 8 2008, 23:53
Post
#1
|
|
|
Member Group: Full Members Posts: 134 Joined: 18-February 06 Member No.: 2773 Mp3tag Version: 2.46a |
anyone have a regex to return a substring preceding or following the first occurrence of a delimiter?
|
|
|
|
Sep 9 2008, 05:12
Post
#2
|
|
![]() Member Group: Full Members Posts: 4129 Joined: 26-May 06 From: Wuppertal, Germany, Planet Earth Member No.: 3194 Mp3tag Version: 2.54 |
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 -------------------- * Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥ |
|
|
|
Sep 9 2008, 08:51
Post
#3
|
|
|
Member Group: Full Members Posts: 134 Joined: 18-February 06 Member No.: 2773 Mp3tag Version: 2.46a |
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 ":;," This post has been edited by egd: Sep 9 2008, 08:55 |
|
|
|
Sep 9 2008, 13:08
Post
#4
|
|
![]() Member Group: Full Members Posts: 4129 Joined: 26-May 06 From: Wuppertal, Germany, Planet Earth Member No.: 3194 Mp3tag Version: 2.54 |
$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 -------------------- * Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥ |
|
|
|
Sep 9 2008, 21:34
Post
#5
|
|
|
Member Group: Full Members Posts: 134 Joined: 18-February 06 Member No.: 2773 Mp3tag Version: 2.46a |
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?
This post has been edited by egd: Sep 9 2008, 21:34 |
|
|
|
Sep 10 2008, 06:11
Post
#6
|
|
![]() Member Group: Full Members Posts: 4129 Joined: 26-May 06 From: Wuppertal, Germany, Planet Earth Member No.: 3194 Mp3tag Version: 2.54 |
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 -------------------- * Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥ |
|
|
|
Sep 10 2008, 06:37
Post
#7
|
|
|
Member Group: Full Members Posts: 134 Joined: 18-February 06 Member No.: 2773 Mp3tag Version: 2.46a |
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) |
|
|
|
Sep 10 2008, 08:07
Post
#8
|
|
![]() Member Group: Full Members Posts: 4129 Joined: 26-May 06 From: Wuppertal, Germany, Planet Earth Member No.: 3194 Mp3tag Version: 2.54 |
I'd tried it and got no result, hence my asking. ... Look at http://help.mp3tag.de/en/main_scripting.html QUOTE $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 This post has been edited by DetlevD: Sep 10 2008, 08:08 -------------------- * Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥ |
|
|
|
Sep 10 2008, 10:42
Post
#9
|
|
|
Member Group: Full Members Posts: 134 Joined: 18-February 06 Member No.: 2773 Mp3tag Version: 2.46a |
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" |
|
|
|
Sep 10 2008, 14:21
Post
#10
|
|
|
Member Group: Full Members Posts: 134 Joined: 18-February 06 Member No.: 2773 Mp3tag Version: 2.46a |
I've gotten it working
seems one has to to remove the "'" on either side of '[:;,]+' for the expression to evaluate. thanks again |
|
|
|
Sep 10 2008, 15:52
Post
#11
|
|
![]() Member Group: Full Members Posts: 4129 Joined: 26-May 06 From: Wuppertal, Germany, Planet Earth Member No.: 3194 Mp3tag Version: 2.54 |
I've gotten it working I'm glad to hear this! ... 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 -------------------- * Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥ |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 18th May 2013 - 10:28 |