简体   繁体   English

正则表达式替换Notepad ++中两个'之间的空格

[英]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' '([^' ]+) ([^']+)''\\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+(.*?)' 找到: '(.*?)\\s+(.*?)'

replace with : '\\1', '\\2' 替换为: '\\1', '\\2'

demo here : http://regex101.com/r/yC5tF7/1 演示在这里: http : //regex101.com/r/yC5tF7/1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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