inserting characters in mutiple locat`ions

A swapping-ground for Regular Expression syntax

inserting characters in mutiple locat`ions

Postby loggyboy » Wed Aug 28, 2019 12:41 pm

I;m sure this can be done and has most likely been answered before, but searching for the right term is hard.

I would like to add in an '!' to either side of a single character, example below:

Original Name:
ABCD TITLE FILE A REST OF NAME.abc
Target Name:
ABCD TITLE FILE !A! REST OF NAME.abc

I dont want to use position as as sometimes the length of title will change: ie:

ABCDE LONGTITLE FILE A REST OF NAME.abc
ABCDE LONGTITLE FILE !A! REST OF NAME.abc

Can some one guide me?
loggyboy
 
Posts: 2
Joined: Wed Aug 28, 2019 12:36 pm

Re: inserting characters in mutiple locat`ions

Postby therube » Wed Aug 28, 2019 8:02 pm

There is a lot that this does not account for...
Basic idea should be OK...
Understand & test prior to committing...


1:RegEx
Code: Select all
Match:  (.*)\s(\S)\s(.*)
Replace:  \1 --- !\2! --- \3

(I've added --- for "readability".)

Match everything, greedily, up to the last <space>Single_CHAR<space> combination.
Then just stick some ! in there & write it back out.

Sukiyaki - A Taste of Honey.mp3
Sukiyaki - --- !A! --- Taste of Honey.mp3
(Matches A)

Dave Stewart & Barbara Gaskin - Eight Miles High.mp3
Dave Stewart & Barbara Gaskin --- !-! --- Eight Miles High.mp3
(Matches - rather then &)

Fails:
A Kick In The Teeth.mp3
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: inserting characters in mutiple locat`ions

Postby loggyboy » Thu Aug 29, 2019 10:17 am

Thank you, will trial and let you know how it goes. :)
loggyboy
 
Posts: 2
Joined: Wed Aug 28, 2019 12:36 pm


Return to Regular Expressions


cron