Change 2nd instance of character

A swapping-ground for Regular Expression syntax

Change 2nd instance of character

Postby exraflad » Thu Jun 16, 2016 9:58 am

Is it possible to use bulkrename to rename filenames where there is more than one instance of a character but only rename the 2nd instance.

i.e
forms_weekly_january
to
forms_weekly~january

Thanks
exraflad
 
Posts: 2
Joined: Thu Jun 16, 2016 9:48 am

Re: Change 2nd instance of character

Postby Admin » Fri Jun 17, 2016 1:23 am

Use RegExp (1)

Match :
(.*?)_(.*?)_(.*)

Replace :
\1_\2~\3

----------------
Note:
Adding a ? on a quantifier (?, * or +) makes it non-greedy.
So (.*) matches any characters (greedy)
So (.*?) matches any character (non-greedy=matching stops at first match)
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Change 2nd instance of character

Postby exraflad » Sat Jun 18, 2016 9:50 pm

Thanks, not used reg expressions before but will have a play

Again Thanks
exraflad
 
Posts: 2
Joined: Thu Jun 16, 2016 9:48 am


Return to Regular Expressions


cron