Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ Regex Replace doesn't work on Notepad++

I tried to search for every word that has
bar-foo and switch them to foo-bar
so I wrote on the find (\w+)-(\w+)
and on the replace $2-$1
and instead of writing foo-bar it wrote $2-$1.

Yes, Regular Expression in search mode is on.
It seems that the Replace Regex doesn't work and been taken literally

like image 269
Asaf Avatar asked Aug 24 '10 12:08

Asaf


People also ask

How do you replace regex in Notepad?

A normal “Find and Replace” can't do that, but it's possible with “Regular Expressions”. In Notepad++ press Ctr+H to open the “Find and Replace” window. Under Search Mode: choose “Regular expression” and then check the “matches newline” checkbox. You should see closing </p> tags at the end of each line.

Does regex work in notepad?

Using Regex to find and replace text in Notepad++ And also ensure the 'Regular expression' radio button is set. Check that your word wrap is switched off so that you actually see the text get modified. In this example we just replace the match with empty text.

How do you use the Replace function in notepad?

Replacing text within NotepadOpen the text file in Notepad. Click Edit on the menu bar, then select Replace in the Edit menu. Once in the Search and Replace window, enter the text you want to find and the text you want to use as a replacement.


2 Answers

With notepad++ you'll need to use \2-\1 as the replacement string.

Sources :
Mark's Speechblog

like image 178
Colin Hebert Avatar answered Oct 21 '22 19:10

Colin Hebert


Use \2 \1 in the replace field.

Notepad++ uses the linux like \1 syntax instead of $1

like image 21
Amarghosh Avatar answered Oct 21 '22 19:10

Amarghosh