REGEX in Notepad++ find/replace

拈花ヽ惹草 提交于 2019-12-20 07:17:04

问题


Is it possible to use the value of a regex in the "FIND" part of a find/replace in Notepad++ ?

Here's what i have :

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

the value to replace is the 106th character in my file. 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)

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.

The whole purpose of this is to have this set on a hotkeyed macro so it can be done quickly and often.


回答1:


I think you want something along these lines:

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.




回答2:


You could do:

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

Make sure you have checked Regular expression BUT NOT dot matches newline

then click on Replace all

This will capture in group 1 the first 105 characters in each line.



来源:https://stackoverflow.com/questions/37171292/regex-in-notepad-find-replace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!