add dash to file name

A swapping-ground for Regular Expression syntax

add dash to file name

Postby newuser » Tue Aug 05, 2014 7:33 pm

Hello,

I want to add a dash after the second word in the file name:

one two other words in file name = one two - other words in file name

After reading the forum it seems (.+) stand for the first word and \s stands for spaces according to the help manual so I tried:

(.+)\s(.+)\s(.+)
I thought that would mean the first word then a space then the second word then a space then the rest of the file name.
I used this to replace:
\1 \2 - \3

I spent two days trying different things but can only get the dash to go at the end and not where I want it. I hope someone will explain what I am doing wrong. I want to be able to move to the dash to various places also and it seems impossible.
newuser
 
Posts: 1
Joined: Tue Aug 05, 2014 6:48 pm

Re: add dash to file name

Postby Stefan » Fri Aug 08, 2014 10:20 pm

 

Bravo, you where very close already, but...

RegEx works greedy, so let it work lazy by adding "?" after your expression:

FROM:
one two other words in file name.ext
TO:
one two - other words in file name.ext

USE:
RegEx(1)
Find: (.+?)\s(.+?)\s(.+)
Repl: \1 \2 - \3


 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions