Home Download Buy Blog Forum Support

Regex replace backreference inserting unwanted space

Regex replace backreference inserting unwanted space

Postby jtara on Wed Oct 24, 2012 2:19 am

I have a file that has lines like this:

Code: Select all
- { file: mookerawa, image: Mokwatersweb2.jpg, caption: Mookerawa Waters State Park, Lake Burrendong }


I want to quote the captions.

I tried:

Find What:

Code: Select all
caption:\s*(.*)\s*\}


Replace With:

Code: Select all
caption: "\1" }


I thought maybe I had to escape the quotes in the replacement, but that doesn't change anything.

Is there a bug, or am I missing something?
I am getting an unwanted space between the end of caption string and the end bracket:

Code: Select all
- { file: mookerawa, image: Mokwatersweb2.jpg, caption: "Mookerawa Waters State Park, Lake Burrendong " }
jtara
 
Posts: 4
Joined: Wed Oct 24, 2012 2:09 am

Re: Regex replace backreference inserting unwanted space

Postby skuroda on Wed Oct 24, 2012 3:15 am

Think it has to do with regular expressions being greedy.

Try this for your find regex.
Code: Select all
caption:\s*(.*?)\s*\}
skuroda
 
Posts: 681
Joined: Fri Oct 05, 2012 8:11 am

Re: Regex replace backreference inserting unwanted space

Postby adzenith on Wed Oct 24, 2012 7:14 pm

If they all end with a space before the closing brace, you can also change \s* to \s+.
adzenith
 
Posts: 1215
Joined: Mon Oct 19, 2009 9:12 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 43 guests