简体   繁体   English

记事本中的REGEX ++查找/替换

[英]REGEX in Notepad++ find/replace

Is it possible to use the value of a regex in the "FIND" part of a find/replace in Notepad++ ? 是否可以在Notepad ++中的查找/替换的“查找”部分中使用正则表达式的值?

Here's what i have : 这是我所拥有的:

FIND: ^.{105}.*(.)
REPLACE: \r\n

the value to replace is the 106th character in my file. 要替换的值是文件中的第106个字符。 let's say it's an ~ 比方说~

now the find/replace should find & replace all occurrence of ~ and replace all of them by '\\r\\n' (the ~ represent the end of line character) 现在,查找/替换应该查找并替换所有〜的出现,并将所有替换为'\\ r \\ n'(〜代表行尾字符)

It doesn't work, it replace the whole string instead of the 106th char and only replace once instead of multiple time on the file. 它不起作用,它将替换整个字符串而不是第106个字符,并且仅替换一次而不是多次替换文件。

The whole purpose of this is to have this set on a hotkeyed macro so it can be done quickly and often. 这样做的全部目的是将其设置在热键宏上,以便可以快速,经常地完成它。

I think you want something along these lines: 我认为您需要遵循以下原则:

Find: ^(.{105}.) Replace: \\1\\r\\n Find: ^(.{105}.) Replace: \\1\\r\\n

You need to wrap the thing in a capture group otherwise your ^ will force it to only match the beginning of the line. 您需要将事物包装在捕获组中,否则您的^将迫使其仅与行的开头匹配。 You'll also need to include the first capture group as part of the replacement string so it won't nuke the entire matching. 您还需要将第一个捕获组作为替换字符串的一部分包含在内,这样就不会破坏整个匹配项。

You could do: 您可以这样做:

Find what: ^(.{105}). 查找内容: ^(.{105}).
Replace with: $1\\r\\n 替换为: $1\\r\\n

Make sure you have checked Regular expression BUT NOT dot matches newline 确保您已检查Regular expression但不能dot matches newline

then click on Replace all 然后点击全部替换

This will capture in group 1 the first 105 characters in each line. 这将在组1中捕获每行的前105个字符。

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

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