IPB

Welcome Guest ( Log In | Register )

> Notice!

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.

 
Reply to this topicStart new topic
> Using regex to return a substring
egd
post 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?
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 9 2008, 05:12
Post #2


Member


Group: Full Members
Posts: 5031
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



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


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
egd
post 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
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 9 2008, 13:08
Post #4


Member


Group: Full Members
Posts: 5031
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



$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 ♥
Go to the top of the page
 
+Quote Post
egd
post 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
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 10 2008, 06:11
Post #6


Member


Group: Full Members
Posts: 5031
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



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


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
egd
post Sep 10 2008, 06:37
Post #7


Member


Group: Full Members
Posts: 134
Joined: 18-February 06
Member No.: 2773
Mp3tag Version: 2.46a



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)
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 10 2008, 08:07
Post #8


Member


Group: Full Members
Posts: 5031
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



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.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 ♥
Go to the top of the page
 
+Quote Post
egd
post Sep 10 2008, 10:42
Post #9


Member


Group: Full Members
Posts: 134
Joined: 18-February 06
Member No.: 2773
Mp3tag Version: 2.46a



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" sad.gif
Go to the top of the page
 
+Quote Post
egd
post 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 smile.gif

seems one has to to remove the "'" on either side of '[:;,]+' for the expression to evaluate.

thanks again
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 10 2008, 15:52
Post #11


Member


Group: Full Members
Posts: 5031
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.63



QUOTE (egd @ Sep 10 2008, 15:21) *
I've gotten it working smile.gif

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


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 31st October 2014 - 11:37