Regular Expression Search and Replace via Command Line (Editplus)

Editplus is definitely my favorite text editor but it does not entirely support Regular Expression. Below is an example of when Editplus has failed me:

Editplus-regex

So, I used the regular expression .*<table.*\n.*<tr>\n.*<td>. This unexpectedly returned everything from the beginning of the file down to the <td>. Basically it seems to have a little bit of trouble with multi-line regular expressions.

My solution to this problem was to develop a little regular expression command line program and add it as an Editplus user tool. An added benefit to creating this application is I can now do Regular Expression search and replace via the command line. At the time of creating this application I did not know about Powershell as that would have provided the same functionality. But this little application works so I will stick with it for now.

So, how does the search and replace program work? If you type SearchReplace.exe at the command line you will get the following:

Usage: searchReplace.exe "regular expression" "replacement string" file.txt

Pretty simple ehh?  Note: if you happen to have double quotes in your regular expression they will need to be escaped.

Now to set this up with Editplus just go to Tool —> Preferences —> User Tools and put in the following values:

Command: SearchReplace.exe
Argument: "$(Prompt)" "$(Prompt)" $(FileName)
Initial: $(FileDir)
Check: Run as text filter

When this user tool is run the first pop up box will be where you put the regular expression and the second will be the replacement string.

At this point I have to give a little warning that I have not thoroughly tested this program and I am not liable for any data loss caused by this program. If you happen to encounter any problems let me know. 

Related Posts:

One Response to “Regular Expression Search and Replace via Command Line (Editplus)”

  1. mike Says:

    Bugreport:
    this tool changing charset of the parsed text.

    when source contain cyrillic chars in the utf-8 then result is in the 866 codepage

    when source contain cyrillic chars in other charset (f.e. windows-1251) then result is broken:
    ?????? ? ????? ?? "?????? ???"
    ???? ??????

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.