notepad++正则表达式查找并替换括号之间的空格
notepad++ regex find and replace spaces between brackets
在记事本++中,想改变这个:
[City tier] [nvarchar](max) NULL,
[Counting unit] [nvarchar](max) NULL,
对此:
[City_tier] [nvarchar](max) NULL,
[Counting_unit] [nvarchar](max) NULL,
我用[\w+(\s)\w+]定位了这两条记录,但是当我用\1_替换时,我得到了
_ [nvarchar](max) NULL,
_ [nvarchar](max) NULL,
您可以使用此 PCRE 正则表达式进行搜索:
((?:\[|(?!^)\G)[^]\s]*)\s
并替换为:
_
正则表达式详细信息:
(
: 开始捕获组#1
(?:
: 启动非捕获组
\[
:匹配一个[
|
: 或
(?!^)\G
: 从上一场比赛结束重新开始比赛
)
:结束非捕获组
[^]\s]*
:匹配 0 个或多个不是空格且不是 ]
的字符
)
: 结束捕获组#1
\s
:匹配一个空格
Notepad++ 支持 \G
和 \K
,您可以使用
(?:\G(?!\A)|\[)[^][\s]+\K\s+
这需要用下划线代替,参见a demo on regex101.com。
这归结为
(?: # non-capturing group (?:...)
\G(?!\A) # match after the last match but not at the very start
| # or
\[ # a "[" literally
)
[^][\s]+\K # not "]" nor "[" nor spaces, \K -> "forget everything on the left"
\s+ # whitespace characters
实际上,此构造仅匹配方括号内的空格。
在记事本++中,想改变这个:
[City tier] [nvarchar](max) NULL,
[Counting unit] [nvarchar](max) NULL,
对此:
[City_tier] [nvarchar](max) NULL,
[Counting_unit] [nvarchar](max) NULL,
我用[\w+(\s)\w+]定位了这两条记录,但是当我用\1_替换时,我得到了
_ [nvarchar](max) NULL,
_ [nvarchar](max) NULL,
您可以使用此 PCRE 正则表达式进行搜索:
((?:\[|(?!^)\G)[^]\s]*)\s
并替换为:
_
正则表达式详细信息:
(
: 开始捕获组#1(?:
: 启动非捕获组\[
:匹配一个[
|
: 或(?!^)\G
: 从上一场比赛结束重新开始比赛
)
:结束非捕获组[^]\s]*
:匹配 0 个或多个不是空格且不是]
的字符
)
: 结束捕获组#1\s
:匹配一个空格
Notepad++ 支持 \G
和 \K
,您可以使用
(?:\G(?!\A)|\[)[^][\s]+\K\s+
这需要用下划线代替,参见a demo on regex101.com。
这归结为
(?: # non-capturing group (?:...)
\G(?!\A) # match after the last match but not at the very start
| # or
\[ # a "[" literally
)
[^][\s]+\K # not "]" nor "[" nor spaces, \K -> "forget everything on the left"
\s+ # whitespace characters
实际上,此构造仅匹配方括号内的空格。