INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: RegEx Find & Replace  (Read 1141 times)

Sangie

  • Recent member
  • *
  • Posts: 45
RegEx Find & Replace
« on: June 24, 2020, 11:20:08 pm »

I can't figure out how to use Find & Replace with RegEx. I'm wanting to replace all instances of the following to a semicolon in the artist field:
 &, feat., vs., feat, vs, pres.
This way artists can all be tagged properly.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: RegEx Find & Replace
« Reply #1 on: June 24, 2020, 11:55:01 pm »

You could do each variant one at a time just using the Replace() function in the [Artist] column.

=Replace([Artist],/&/,,;)

Would fix the "&," instances. i.e. It will convert;
Angelo Badalamenti &, Barry Short;Mary Long &, Fred Wide
to
Angelo Badalamenti;Barry Short;Mary Long;Fred Wide


Test using an expression column first, then apply to the [Artist] column.

Backup your Library before testing and applying to all files though!


PS: I only suggest this because I can't write Regex!  ;D
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Sangie

  • Recent member
  • *
  • Posts: 45
Re: RegEx Find & Replace
« Reply #2 on: June 25, 2020, 12:15:36 am »

You could do each variant one at a time just using the Replace() function in the [Artist] column.

=Replace([Artist],/&/,,;)
Artist column? I'm talking about the tool Library Tools -> Find and Replace. Sounds like you're describing a better way. Would you mind going into further details?
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: RegEx Find & Replace
« Reply #3 on: June 25, 2020, 12:50:24 am »

Sorry, I focused on the Regex part of your post. I've been playing with too many MC functions and Regex lately.

The "Library Tools -> Find and Replace" function will do what you want, without the need for Regex. Just select the [Artist] field and set the Find to " &, " and Replace to ";" all without quotes, but note the spaces. You can apply that to just one file, and if it works, apply it to many. Then repeat for all variations you want to fix.

What I'm talking about is the ability of MC to update fields themselves by editing the field and entering an Expression, prefixed by an equals sign, into the field. What I would call "In Place Editing". MC reads the content of the field, applies the Expression to it, and write it back to the field. It's a neat trick, and the way I do most edits of that type. Hence I didn't think of the "Find and Replace" function when I read your thread.

One advantage of using the "Find and Replace" function is that you don't have to worry escaping certain characters like "&" and "," using the "/" Escape Character, which is why my expression included "/&/," which escaped the "&" and "," characters, preventing them from being treated as part of the expression function.

The attached image shows another example using your " feat., " variant, which escapes the spaces either side so they are also removed.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Sangie

  • Recent member
  • *
  • Posts: 45
Re: RegEx Find & Replace
« Reply #4 on: June 29, 2020, 02:45:18 am »

The "Library Tools -> Find and Replace" function will do what you want, without the need for Regex. Just select the [Artist] field and set the Find to " &, " and Replace to ";" all without quotes, but note the spaces. You can apply that to just one file, and if it works, apply it to many. Then repeat for all variations you want to fix.
It will do it one at a time which will be annoying. I want it to look for a list of conjunctions that could appear between artists.

What I'm talking about is the ability of MC to update fields themselves by editing the field and entering an Expression, prefixed by an equals sign, into the field. What I would call "In Place Editing". MC reads the content of the field, applies the Expression to it, and write it back to the field. It's a neat trick, and the way I do most edits of that type. Hence I didn't think of the "Find and Replace" function when I read your thread.
Okay so I go to "Add Expression Column" then put in the expression? Okay that's cool. But is it editing the tags directly in the file or just changing how I see it within MC?
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: RegEx Find & Replace
« Reply #5 on: June 29, 2020, 05:50:49 pm »

It will do it one at a time which will be annoying. I want it to look for a list of conjunctions that could appear between artists.

Correct. But you have only listed six conjunctions, so once you understand the process you can select all files in your Library and apply the fix to them all at once. That isn't a big amount of work, and once done, it is done forever. If the Find and Replace doesn't find the conjunction in the [Artist] field of a particular file, it won't make any changes, so selecting all files (or a subset of them) and applying the function won't harm files that don't have the conjunction in the [Artist] field.


Okay so I go to "Add Expression Column" then put in the expression? Okay that's cool. But is it editing the tags directly in the file or just changing how I see it within MC?

No. As I said:
Test using an expression column first, then apply to the [Artist] column.

You edit the actual [Artist] field in a View (my preference) or the Tag Window, and enter the expression as new content for the field. MC evaluates it and updates the field. You don't use an Expression column, except for testing your expression, which is what I showed in the image. You edit the [Artist] field and type or paste in =Replace([Artist],/&/,,;) and MC updates the value in the [Artist] field, removing the "&,".

When you do this, using either method, the fields in MC are updated. If those fields are set to update tags in the actual file, as [Artist] is, then the file tags are updated as well. If there are a lot of changes it could take a while, which is why most people do it in sensible chunks of their Library.


But the Find and Replace function works fine, and is simpler, so use that once on all files in the Library for each conjunction (after testing), and you are done.

Make sure you Backup your Library before starting work.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Sangie

  • Recent member
  • *
  • Posts: 45
Re: RegEx Find & Replace
« Reply #6 on: June 30, 2020, 12:20:37 am »

So because not all artist names need to have the & removed and replaced due to groups like "Above & Beyond" and "Selena Gomez & The Scene" I decided to use smart playlists to find them then I can select the ones that apply. This has worked really well and I'm about done!
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: RegEx Find & Replace
« Reply #7 on: June 30, 2020, 01:31:25 am »

Nice!

Easy really.  ;)
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner
Pages: [1]   Go Up