1

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?

7
  • what do you mean by non breaking space? Commented Jun 6, 2015 at 13:47
  • @karthikmanchala blanks and tabstops I assume Commented Jun 6, 2015 at 13:47
  • yes it's possible but it would help if you gave an example line that you want to run the regex on (and expected output) Commented Jun 6, 2015 at 13:47
  • @karthikmanchala  ? Commented Jun 6, 2015 at 13:48
  • Not sure if notepad++ regex engine is powerful enough for this sort of thing but here is a php solution stackoverflow.com/questions/18581227/… Commented Jun 6, 2015 at 13:56

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, in N++ that just replaces all spaces. Maybe a weakness in N++'s implementation of regex. I'll try to reverse engineer from the demo.
Good idea! Maybe not working for @Kapitano because of \s at the end. Try (?:~|\G(?!^))\S*\K[ ]
@Jonny5 hmm.. maybe.. I tried it with \s in N++ and it works.. in anycase.. updated with your suggestion too.. :)
0

With fixed-width pattern lookbehind regex engines (e.g., 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.