Remove string between 2nd and 3rd comma

A swapping-ground for Regular Expression syntax

Remove string between 2nd and 3rd comma

Postby cmw » Mon Jun 15, 2020 2:56 am

Hi, I've tried to search the forum without luck, so I'm hoping someone can help me out...

I have a group of folders named according to the following structure:
Lastname,Firstname,Date-of-Birth,RecordID
For example, "Mouse,Mickey,1950-12-31,98765"

I want to remove the Date-of-Birth (ie the string between the 2nd and 3rd comma) from the folder name, leaving the preceeding and succeeding commas, such that the example above would become:
"Mouse,Mickey,,98765" (with two commas after Firstname).

So far, the closest I have tried is
Match: (?:([^,]*),){3}
Replace: \1

However, this does the exact opposite of what I want (it removes everything other than the Date-of-Birth).

I appreciate any help!
Chris
cmw
 
Posts: 2
Joined: Mon Jun 15, 2020 2:45 am

Re: Remove string between 2nd and 3rd comma

Postby David » Mon Jun 15, 2020 7:48 am

Match: (.*?)\S(\d\d\d\d\S\d\d\S\d\d)(.*)

Replace: \1,\3
David
 
Posts: 3
Joined: Mon Jun 15, 2020 7:25 am

Re: Remove string between 2nd and 3rd comma

Postby cmw » Mon Jun 15, 2020 7:53 am

David wrote:Match: (.*?)\S(\d\d\d\d\S\d\d\S\d\d)(.*)

Replace: \1,\3


This worked a treat! Many thanks David :D
cmw
 
Posts: 2
Joined: Mon Jun 15, 2020 2:45 am


Return to Regular Expressions