简体   繁体   中英

Regex to replace space between two ' in Notepad++

I have a line that looks like this:

(267, 'Name Surname')

I want to find the space between name and surname, and change it so it will look like this:

(267, 'Name', 'Surname')

What regex substitution should I make?

'([^' ]+) ([^']+)''\\1', '\\2'

This replaces the first space between single quotes. If you remove the space from first [] class, greediness of + ensures that the last space between single quotes is replaced.

The first grouping matches anything after a single quote that doesn't contain single quotes nor spaces. If it was allowed to contain spaces, it will match till the final single quote, but from there it will backtrack as the match needs to be followed by a space.

find : '(.*?)\\s+(.*?)'

replace with : '\\1', '\\2'

demo here : http://regex101.com/r/yC5tF7/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM