Add after second occurence, leave the rest be

A swapping-ground for Regular Expression syntax

Add after second occurence, leave the rest be

Postby dooniem » Wed Apr 20, 2016 12:27 pm

Hi. I've been browsing and browsing in hopes of putting the information together by myself, but I give in. This is me asking humbly for some help.

I several files with this type of name:
2013.10.10_D_Location_Description.pdf

What I want is to add: "E-mail" to this string, after the Location.
2013.10.10._D_Location_E-mail_Description.pdf

If it's easier to read it this way, I want to go from:
[date]_[identifier]_[Location]_[Description].pdf
To-> [date]_[identifier]_[Location]_[E-mail]_[Description].pdf

I have assumed RegEx but all I end up with is "E-mail" after the first 3 digits or just at the end of the filename.
Could you please help me with the code for this?
dooniem
 
Posts: 2
Joined: Wed Apr 20, 2016 12:03 pm

Re: Add after second occurence, leave the rest be

Postby Admin » Thu Apr 21, 2016 1:59 am

Try RegEx (1)

Match : (.*)_(.*)_(.*)_(.*)
Replace: \1_\2_\3_E-Mail_\4

thanks
Admin
Site Admin
 
Posts: 2572
Joined: Tue Mar 08, 2005 8:39 pm

Re: Add after second occurence, leave the rest be

Postby dooniem » Thu Apr 21, 2016 6:23 pm

Thanks! It seems so obvious now when I see the completed code!
Thanks for taking your time to answer :)
dooniem
 
Posts: 2
Joined: Wed Apr 20, 2016 12:03 pm


Return to Regular Expressions