Sublime Forum

Regex replace backreference inserting unwanted space

#1

I have a file that has lines like this:

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

I want to quote the captions.

I tried:

Find What:

caption:\s*(.*)\s*\}

Replace With:

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:

- { file: mookerawa, image: Mokwatersweb2.jpg, caption: "Mookerawa Waters State Park, Lake Burrendong " }
0 Likes

#2

Think it has to do with regular expressions being greedy.

Try this for your find regex.

caption:\s*(.*?)\s*\}
0 Likes

#3

If they all end with a space before the closing brace, you can also change \s* to \s+.

0 Likes