Author Topic: Replacement processing in RegExp  (Read 621 times)

Messiaen

  • Jr. Member
  • **
  • Posts: 103
Essentially I'm wondering if the "replace" text used in the tag search/replace function (as well as the $RxReplace() virtual function) is processed for anything other than the normal $nn backreference tokens?

In particular, the \U...\E switches common to RegExp replacements, where the text between \U and \E is converted to upper-case before being pasted in.

As a simple example, if I wanted to capitalize the first letter in a title after a dash mark ("-") I would use:

Code
\-(.)

with the replacement text:

Code
-\U$1\E

Testing with the title "rem-nant" should return as "rem-Nant", except in MB the returned string is "rem-\Un\Eant" which basically means the \U and \E regexp switches are ignored.

I also tested this with the virtual function $RxReplace(<Title>,"\-(.)","-\U$1\E") with the same result.

My original use case for this was more complex, but you get the idea.  For comparison, I ultimately just used the regexp replace function in MP3tag to accomplish this, so I know the syntax is correct, but as MB supports regexp in most things, it would make sense for this too to work.  Unless I'm missing something? :-\

As this could be considered anything from a bug to an oversight or even a "feature" depending on one's point of view, I ask as a general query.

boroda

  • Sr. Member
  • ****
  • Posts: 4636
\U and \E are not standard switches, they are some extensions, see here the reference for regex standard. you could try this plugin, 'change case' command, though it can't do exactly what you have described, maybe it might be useful for you in some other way.

EDIT: also, try 'advanced search & replace' command, one of 'change case' presets. select preset, click 'copy' button and modify preset copy.
Last Edit: August 19, 2022, 03:46:01 PM by boroda

Messiaen

  • Jr. Member
  • **
  • Posts: 103
Well, to be fair, according to www.regular-expressions.info, which serves as a common-enough reference site, there are a great many of these replace-specific switches defined in the common Perl-regexp form.  Like I said, MP3tag accepts it as normal, as do other engine implementations (Notepad++, PCRE2, etc.)  I can't speak for how or why .NET arrives at its standards, but as I'm a K&R C man at heart myself, that more modern stuff's beyond me.  ;)

I do use your ATR plugin quite often (and thank you profusely for it!), but you're right it didn't fit this exact use-case.  While MP3tag is a decent workaround, it doesn't provide MB's or ATR's "preview" function, which is so very necessary when messing around with regular expressions.  As I said, my original purpose was more complex than the example I used, which is how I ran across this in the first place.

I did search the forum for regexp-related posts, but no one else seems to have encountered this same "need" before, so maybe there's not much call for it overall.  :-\
Last Edit: August 19, 2022, 04:25:02 PM by Messiaen

The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1282
I do use your ATR plugin quite often (and thank you profusely for it!), but you're right it didn't fit this exact use-case.  While MP3tag is a decent workaround, it doesn't provide MB's or ATR's "preview" function, which is so very necessary when messing around with regular expressions.  As I said, my original purpose was more complex than the example I used, which is how I ran across this in the first place.

You can preview expression results in mp3tag using any of the Convert toolbar actions. Tag - Tag is what you're looking for and is also accessible with ALT + 5.

Messiaen

  • Jr. Member
  • **
  • Posts: 103
Ah, thank you for that - that's what happens when I get too comfortable using "Actions (Quick)" (which eliminates the preview) instead of the proper functions underneath.  MP3tag is not the most immediately friendly program, which is often true of powerful utilities.

I appreciate the tip.  :)