33

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

Asaf
  • 8,106
  • 19
  • 66
  • 116
  • How is SO less appropriate of a place to answer this question than SU? – BoltClock Aug 24 '10 at 12:54
  • 1
    who said it was less appropriate ? I guess it's a borderline topic, since notepad++ is used 99% for programming.. and Regex could be considered as programming... dunno :I – Asaf Aug 24 '10 at 13:26
  • 1
    I was referring to the two people who voted to move to Super User. – BoltClock Aug 27 '10 at 21:01
  • 8
    ***Update:*** For Notepad++ version 6.0 or newer (=> 6.0), you can use `\1` **and** `$1` [(a detailed explanation)](http://stackoverflow.com/questions/11970405/notepad-backreference-regex-syntax-in-search-replace-1-or-1/11970406#11970406). – amiregelz Aug 25 '12 at 17:40

2 Answers2

54

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

Sources :
Mark's Speechblog

Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
  • For instance, why when I try to search for (empty|isset) it doesn't find anything although there's 'empty' inside the doc? – Asaf Aug 24 '10 at 13:41
9

Use \2 \1 in the replace field.

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

Pang
  • 9,564
  • 146
  • 81
  • 122
Amarghosh
  • 58,710
  • 11
  • 92
  • 121