ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > Living Room

Text editor - macro - multiple regex find and replaces

(1/4) > >>

dcwul62:
Up front, I am totally unfamiliar with the following.

I would like to do this:
have a text in a text-editor
then run a macro (or something like that) that performs multiple find-and-replace actions based on regex
on selected text

so, a kind of
find regex #1
replace with so and so
find regex #2
replace with another so and so
find regex #3
etc.

probably it should be done in a script(?)
I can do a find and replace one by one only but that is a lot of work.

I don't know if there are text editors that can create macro's using multiple regex.

Vainly spent a -lot- of time on finding anything that may lead me into the right direction.

Anyone out there has a tip?

I believe there are no macro recorders that can record multiple find-and-replace actions.

Thanks!

=

Ath:
Notepad++ ?

MilesAhead:
For repetitive commands you may wish to take a look at vim

It is free and is capable of operations difficult in most free text editors.  It has been years since I have used it.  So I forget the particular commands.  But I can remember doing things like cutting all but the first sentence in each paragraph in a file and pasting it at the bottom of the file.  Something like that in a lengthy file can quickly tire you out if you physically do the cut and paste operations manually.  With vi(on which vim is based) it was done with one command.

I keep saying I will get back into using it myself.  But I procrastinate.  :)

I am sure it supports regular expressions.

Also for regex substitutions on each line of text processing entire files see the Linux "sed" tool.  There are many "one-liners" you can find on the web.  There is a good chance what you want to do is already possible using one of them.  But briefly sed is a "stream editor."  It is used on the command line.  You feed a file(which can also be standard input such as via a pipe on the command line) into it and it processes the text using the command and outputs the result.  You can find sed for Windows as freeware if you are using Windows.

Note that with sed one-liners for Linux the file separator is a forward slash('/') instead of a backslash('\') and for that reason it is a good idea to look for a one-liner page for the Windows version of sed.  That would save you having to edit the one-liner, which somewhat defeats the purpose of finding a "canned" solution to the problem.  :)

You may be able to find a newer version of sed for Windows than this but for command line tools it is possible they have not changed all that much since 2010 anyway.

Tuxman:
Also, Emacs. Although both Vim and Emacs lack PCRE support (except you call Perl from them).  :)

rjbull:
You could do it with Notetab Pro, which supports PCRE, though I'm not sure if the latest version.  I don't know if freeware Notetab Light can also do "clipbook programming," their name for Notetab's macro language.

Otherwise, MilesAhead's suggestion of sed is sound.  Another useful source is the seder's grab bag.  If sed can't do what you want, or its syntax is too cryptic, try AWK; Awk  FAQ.  Notetab Pro knows how to run AWK scripts, also Perl scripts.

Another approach: try Andrew Pipkin's Minitrue, a Search / Replace Utility (Named after Orwell's "1984").  It supports extended regular expressions.  If you're on Windows, you might want to try the version of Minitrue recompiled by Jason Hood to better support Windows LFNs.

Navigation

[0] Message Index

[#] Next page

Go to full version