Skip to main content
Topic: Feature request: $regexp function (Read 631 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.

 
SimplePortal 1.0.0 RC1 © 2008-2018