[prog] replacement strings

Miriam English mim at miriam-english.org
Sun May 23 23:37:30 UTC 2010


Does anybody know of anything (editor or shell command) which can find 
and replace patterns like the following. I don't really care about 
particular syntax, just so long as something exists that does the job.

search pattern: \(foo[0-9]\)\(b[au]r\)
replace pattern: \2 \1

This searches for "foo" followed by a digit, then "bar" or "bur", then 
replaces it with what it found, but in a different order -- in this case 
"bar" or "bur" followed by "foo" and the digit that came after it.

That is, I'm looking for the ability to search for arbitrary patterns, 
and using some kind of separator, in this example \( \), to mark found 
items to be used as replacement strings. The first pattern gets the "\1" 
label, the second "\2", the third "\3" and so on. The replacement labels 
can be used more than once (for example "\1\1\3 \1") and in any order.

Anybody know of something like that?

Years ago, when I still used MSWindows, I bought a truly wonderful 
programmer's text editor called TextPad which has the most flexible and 
useful search-replace functions I've ever encountered. This particular 
ability to name search patterns and use them in the replace is one that 
I use an awful lot. I would love to be able to drop TextPad (I hate 
having to use wine) and use a linux-native program for this. Anybody 
know of something?

Cheers,

	- Miriam

-- 
If you don't have any failures then you're not trying hard enough.
  - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
-----
Website: http://miriam-english.org
Blog: http://miriam_e.livejournal.com



More information about the Programming mailing list