#1 2016-03-19 05:46

dak4482
Member
Registered: 2016-03-19
Posts: 3

Formatting years using RegEx

hi all,

I'm VERY new to regex-type text manipulation and my problem is fairly simple but I just can't get it to work. I have a group of music files (1000's of them) such as:

Counts (4) (Bobby Comstock & The) - The Beatle Bounce 1964 Lawn 229.mp3
Counts (4) (Bobby Comstock & The) - The Chicken Back - 63 Lawn 217.mp3
Counts (4) (Bobby Comstock & The) - The Garden Of Eden - 61 Festival 25000 ERROR.txt
Counts (4) (Bobby Comstock & The) - The Wayward Wind - 1960 Mohawk 124.mp3
Counts (4) (Bobby Comstock & The) - This Little Love Of Mine - 1963 Lawn 219.mp3
Counts (4) (Bobby Comstock & The) - Tra-La-La (I'm So Happy) - 1961 Marlee 104 Not Listed.mp3
Counts (4) (Bobby Comstock & The) - Your Big Brown Eyes - 1963 Jubilee 5396.mp3

and I want to change the part of the string "- 1963" using a wildcard for the last two digits of the year)

to just "- 63" again using wild cards for the last two digits of the year. In other words replace the string "dash, space, 4 digit year" with "dash, space, last 2 digits of year".

I was assuming a search on - 19??
and replacing with - ?? would work but obviously I am missing some syntax notations.

A second one would be replacing just the " 1963 " (spaces before and after the year as in the first entry) with "- 63 "

Anyone willing to help?

Thx in advance

Dan

Offline

#2 2016-03-19 13:39

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,479

Re: Formatting years using RegEx

Hello Dan,

Your idea was correct, you are just missing grouping and substitutions.

I want to change the part of the string "- 1963" using a wildcard for the last two digits of the year)

RegEx: Replace expression "- 19(\d\d)" with "- $1" (skip extension)

A second one would be replacing just the " 1963 " (spaces before and after the year as in the first entry) with "- 63 "

RegEx: Replace expression " 19(\d\d)" with " - $1" (skip extension)

You can also do both operations in one rule:
RegEx: Replace expression "\s*-?\s*\b19(\d\d)\b" with " - $1" (skip extension)

The output will be:

Counts (4) (Bobby Comstock & The) - The Beatle Bounce - 64 Lawn 229.mp3
Counts (4) (Bobby Comstock & The) - The Chicken Back - 63 Lawn 217.mp3
Counts (4) (Bobby Comstock & The) - The Garden Of Eden - 61 Festival 25000 ERROR.txt
Counts (4) (Bobby Comstock & The) - The Wayward Wind - 60 Mohawk 124.mp3
Counts (4) (Bobby Comstock & The) - This Little Love Of Mine - 63 Lawn 219.mp3
Counts (4) (Bobby Comstock & The) - Tra-La-La (I'm So Happy) - 61 Marlee 104 Not Listed.mp3
Counts (4) (Bobby Comstock & The) - Your Big Brown Eyes - 63 Jubilee 5396.mp3

P.S. You might want to have a look at the manual for regular expressions.

Offline

#3 2016-03-19 20:03

dak4482
Member
Registered: 2016-03-19
Posts: 3

Re: Formatting years using RegEx

Thx alot. It worked perfect. Time to start studying that manual with a little more understanding.

Dan

Offline

Board footer

Powered by FluxBB