Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Feature request: $regexp function (Read 2293 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Feature request: $regexp function

Haven't seen any requests for, so:

$regexp(str,expr,replace)

Replaces the pattern specified by the regular expression expr in the string x by replace.

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.


Re: Feature request: $regexp function

Reply #2
Meant to add, I just was lazy and copied that from the mp3tag help files.

The 4th optional parameter is not really required because.
(?i) is the switch in regular expression for turn off case-sensitive
(?-i) is the switch in regular expression for turn on case-sensitive

This is better because you can turn it off/on inside your regular expression.

Re: Feature request: $regexp function

Reply #3
+1 to this request.  For me, I'd leave case sensitivity enabled by default, which usually the case for PCRE, see regex flags here https://regex101.com/ (click the '/g').  If possible, I'd incorporate the PCRE flags as the fourth optional parameter.

For Wolfgang Amadeus Mozart > Mozart, Wolfgang Amadeus:

$regexp as proposed by stevehero:
Code: [Select]
$regexp(str,expr,replace,optional flag)
Code: [Select]
$regexp(%Composer%,'(^.*)(?:\s)(\w+$)',$2', '$1,i) [note: the case insensitive "i" flag is not really needed here]

$regexp PCRE-style as seen in https://regex101.com without the fourth optional parameter, as it's already incorporated.  Pro's: less need to segregate regex search and replace, two parameters instead of potentially four; easily debugged with help from others using https://regex101.com/.  Con: might be a bit more confusing to users who are not used to unix-style regex search and replace
Code: [Select]
$regexp(%field%,'/search/replace/optional flags')
Code: [Select]
$regexp(%Composer%,'/(^.*)(?:\s)(\w+$)/$2, $1/i') [note: the case insensitive "i" flag is not really needed here]
Code: [Select]
$regexp(%Composer%,'/(^.*)(?:\s)(\w+$)/$2, $1/')

Currently in fb2k:
Code: [Select]
$right($ifgreater($meta_num(composer),1,$meta_sep(composer,', ',' & '),%composer%),$sub($len($ifgreater($meta_num(composer),1,$meta_sep(composer,', ',' & '),%composer%)),$strrchr($ifgreater($meta_num(composer),1,$meta_sep(composer,', ',' & '),%composer%),' ')))', '$left($ifgreater($meta_num(composer),1,$meta_sep(composer,', ',' & '),%composer%),$sub($strrchr($ifgreater($meta_num(composer),1,$meta_sep(composer,', ',' & '),%composer%),' '),1))

I know I'll go with the regex options one 100% of the time.

Re: Feature request: $regexp function

Reply #4
this would be great

+1

Re: Feature request: $regexp function

Reply #5
Not sure if any devs read this but thought I'd give it a bump. 

Re: Feature request: $regexp function

Reply #6
+1 for this suggestion too. This would be very useful.

Re: Feature request: $regexp function

Reply #7
Shameless bump.

Re: Feature request: $regexp function

Reply #8
I agree.  A regular expression function could make easy string manipulations that would otherwise require long strings of calls to $strstr(), $substr(), and the like.  A version that returned the index of the match could be helpful, too.  Still, I'd look carefully at performance before I'd think about using in a script that got applied to a large number of files at once, like an autoplaylist or a CUI filter.  Probably the two places I'd be most likely to use regular expressions.

Re: Feature request: $regexp function

Reply #9
+1 for $regex() too (but it seems not to be crowd attracting feature - pity).

Re: Feature request: $regexp function

Reply #10
This is to pad a comment from 1A to 01A and others that are on the Camelot wheel for harmonic mixing in the comment field that has other content also.

This is what I had to use, otherwise, the function was just unreadable, not that this is great.
Code: [Select]
$replace($replace($replace($replace(%comment%,1A,01A,2A,02A,3A,03A,4A,04A,5A,05A,6A,06A,7A,07A,8A,08A,9A,09A,1B,01B,2B,02B,3B,03B,4B,04B,5B,05B,6B,06B,7B,07B,8B,08B,9B,09B),00,0),101,11),102,12)

This is the regex variant I used to use in mp3tag, which is fairly simple when you've got basic regex knowledge.
Code: [Select]
$regexp(%comment%,'(\b[1-9]{1}[A|B])','0$1')