简体   繁体   中英

Regex replace within match

In Notepad++ RegEx, I want to search for all strings starting with a tilde and terminating with \\n, and within each match replace all spaces with non-breaking spaces.

That is, I want to find all instances of \\~.*^ , and within the resulting $0 , replace all [Space]s with [Non-breaking Space] .

Is this possible?

You can use the following to match:

(?:~|\G(?<!^))\S*\K\s

Or try:

(?:~|\G(?!^))\S*\K[ ]

And replace with non breaking space

See DEMO

Credits

With fixed-width pattern lookbehind regex engines (eg, Perl):

s/(~.*?) {2,}/\1 /g

with variable-width pattern lookbehind regex engines:

s/(?<=\~.*) {2,}/  /g

or with Vim:

s/\(\~.*\)@<= \{2,}/  /g

I'm not sure about Notepad++. Hopefully you can work it out based on the above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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