在 Sublime Text 中保留查找替换中的文本
Retaining Text in Find Replace in Sublime Text
我有如下字符串
- 5V6A 6Q2A 6Q 5Q
- FA 7A EQ2A 799Q
- M Y77A279791
- V59 2 5A266
- Q7Q E7Q 7 7AQ2A 7A29
我在查找选项中使用以下方法识别它们
\w.+\d.+(\w+( |$))+
我的问题是我想用相同的替换它,但之后添加了一个“@”符号。我想在 Sublime Text / Notepad++ 中查找替换。我想保留我找到的内容,替换为相同的内容,但末尾带有“@”。所以最后,我希望它在替换后如下所示。
- 5V6A 6Q2A 6Q 5Q @
- FA 7A EQ2A 799Q @
- M Y77A279791 @
- V59 2 5A266 @
- Q7Q E7Q 7 7AQ2A 7A29 @
请帮忙替换。
我想在其中找到它们的数据示例
5V6A 6Q2A 6Q 5Q
Ms.Elena O Peery
Abell (Baltimore)
$Six Million One Hundred Thirty Thousand Seven Hundred Thirty Nine AND Twenty Six%
Twenty Nine Years AND Seven.One%
(Purchase Value Reduction 16.47%)
(Monthly Principal Reduction 7.59%)
(Total Interest Reduction 17.81%)
Mr. Guy L Pittman
E97 99A2A 7Q 9A2999Q
Q5A2A5 6 6A 5 767Q
Mrs.Margaret E No Lents
Juction(Portland)
$Seven Million Nine Hundred Eighty Six Thousand Three Hundred Twenty Three AND Seventeen%
Seventeen Years AND Seven.Eight%
(Purchase Value Reduction 2018%)
(Monthly Principal Reduction 1036%)
(Total Interest Reduction 14.87%)
Ms.Edna R Messerly
7A2YA2AQ27A 7A27AQ2
在 Sublime Text 中,在 find
框中尝试此 (\w.+\d.+(?:\w+(?: |$))+)
,在 @
replace
框中尝试此操作。
只是将其作为答案发布以标记问题已解决。
我仍然不明白组成正则表达式的标准,但如果你的正则表达式工作正常,那么搜索 (\w.+\d.+(\w+( |$))+)
并在记事本 ++
中替换为 @
在您的示例中,以下 "criteria" 可能会有所帮助:
^((?>\h?(?>[A-Z0-9]+)\h?)+)$
# ^ and $ - bind to beginning and end of the line in multiline mode
# the rest matches uppercase letters and digits
# plus an optional whitespace at the beginning / end of the line
# ... and puts them in atomic groups
我有如下字符串
- 5V6A 6Q2A 6Q 5Q
- FA 7A EQ2A 799Q
- M Y77A279791
- V59 2 5A266
- Q7Q E7Q 7 7AQ2A 7A29
我在查找选项中使用以下方法识别它们
\w.+\d.+(\w+( |$))+
我的问题是我想用相同的替换它,但之后添加了一个“@”符号。我想在 Sublime Text / Notepad++ 中查找替换。我想保留我找到的内容,替换为相同的内容,但末尾带有“@”。所以最后,我希望它在替换后如下所示。
- 5V6A 6Q2A 6Q 5Q @
- FA 7A EQ2A 799Q @
- M Y77A279791 @
- V59 2 5A266 @
- Q7Q E7Q 7 7AQ2A 7A29 @
请帮忙替换。
我想在其中找到它们的数据示例
5V6A 6Q2A 6Q 5Q
Ms.Elena O Peery
Abell (Baltimore)
$Six Million One Hundred Thirty Thousand Seven Hundred Thirty Nine AND Twenty Six%
Twenty Nine Years AND Seven.One%
(Purchase Value Reduction 16.47%)
(Monthly Principal Reduction 7.59%)
(Total Interest Reduction 17.81%)
Mr. Guy L Pittman
E97 99A2A 7Q 9A2999Q
Q5A2A5 6 6A 5 767Q
Mrs.Margaret E No Lents
Juction(Portland)
$Seven Million Nine Hundred Eighty Six Thousand Three Hundred Twenty Three AND Seventeen%
Seventeen Years AND Seven.Eight%
(Purchase Value Reduction 2018%)
(Monthly Principal Reduction 1036%)
(Total Interest Reduction 14.87%)
Ms.Edna R Messerly
7A2YA2AQ27A 7A27AQ2
在 Sublime Text 中,在 find
框中尝试此 (\w.+\d.+(?:\w+(?: |$))+)
,在 @
replace
框中尝试此操作。
只是将其作为答案发布以标记问题已解决。
我仍然不明白组成正则表达式的标准,但如果你的正则表达式工作正常,那么搜索 (\w.+\d.+(\w+( |$))+)
并在记事本 ++
@
在您的示例中,以下 "criteria" 可能会有所帮助:
^((?>\h?(?>[A-Z0-9]+)\h?)+)$
# ^ and $ - bind to beginning and end of the line in multiline mode
# the rest matches uppercase letters and digits
# plus an optional whitespace at the beginning / end of the line
# ... and puts them in atomic groups