2

How can I search and replace in way described below. I would like have texts between > and < from this text:

<option value="something">Text a</option>
<option value="abc">Test</option>
<option value="abc1">System</option>

After search and replace I would like have:

Text a+Test+System

So for </option> I can do Search and Replace like that:

</option>\r\n replace to +

But how can I search and replace texts contains different value in here: <option value="something">? I tried with

<option value="*">

but it seems not working.

Can I do these two Search and Replace in one Search and Replace dialog?

Lucas
  • 2,924
  • 8
  • 27
  • 32

3 Answers3

4

You do it like this:

notpad++ search dialog

Make sure Regular Expression is selected.

<option value="(.*)">(.*)< matches your option, the first .* matches everything between the " Place that in side parenthesis (.*) which will create a group you later can refer to. Similarly, the 2. (.*) creates the 2. group, which matches the text between the > and <

Then replace the matched text, using \1 and \2 to refer to the two captured groups: <option value="\1">\2 test system<

nos
  • 223,662
  • 58
  • 417
  • 506
  • Thanks for advice. Because of your advice I found better way: `` replace to `\2+`. But there is still a line break. – Lucas Feb 08 '12 at 11:46
  • After ``. I tried with `\r\n` but search not working during Regular Expression search. – Lucas Feb 08 '12 at 12:31
  • 1
    @Lucas It is not possible to search and replace the carriage return and line feed characters using Notepad++ Regular Expression search mode. As Notepad++ uses Scintilla regex engine and per Scintilla documentation "... \r and \n are never matched because in Scintilla, regular expression searches are made line per line (stripped of end-of-line chars).". See following URL for more information [http://www.scintilla.org/SciTERegEx.html](http://www.scintilla.org/SciTERegEx.html) – Jawwad Alam Feb 10 '12 at 11:09
3

You can achieve this in two simple steps:

First search for <option value=".*"> and select the search mode to regular expression and replace it with empty string.

Secondly, replace </option>\r\n with + and use the search mode extended for this replacement.

Hope this will solve your problem.

Jawwad Alam
  • 322
  • 3
  • 7
  • Thanks. This is working. But is it possible to do these two Search and Replace in one? – Lucas Feb 08 '12 at 11:21
  • @Lucas It is not possible to search and replace the carriage return and line feed characters using Notepad++ Regular Expression search mode. As Notepad++ uses Scintilla regex engine and per Scintilla documentation "... \r and \n are never matched because in Scintilla, regular expression searches are made line per line (stripped of end-of-line chars).". See following URL for more information [http://www.scintilla.org/SciTERegEx.html](http://www.scintilla.org/SciTERegEx.html) – Jawwad Alam Feb 10 '12 at 11:12
  • 1
    @JawwadAlam Recent versions of Notepad++ allow `\r` and `\n` in regular expressions. See http://stackoverflow.com/questions/11389466/multiple-word-search-and-replace-in-notepad/16104946#16104946 for links to documentation. – AdrianHHH Jun 08 '15 at 08:56
  • @Lucas See http://stackoverflow.com/questions/11389466/multiple-word-search-and-replace-in-notepad/16104946#16104946 for a way of combining these two replacements into one. – AdrianHHH Jun 08 '15 at 08:57
0

Step 1: In the replace dialog, switch the search mode to "Regular expression", Search ^<.+\"> and then replace with an empty string.

Step 2: Switch the search mode to normal, Search </option> and replace with an empty string

Step 3. Switch the search mode to Extended(\n, \r ...) search \r\n and replace with +

Good luck.

Hắc Huyền Minh
  • 1,025
  • 10
  • 13
  • Works. But is it possible to do these two Search and Replace in one Search and Replace dialog? – Lucas Feb 08 '12 at 11:32