25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Online Regular Expression Search and Replace Text Editor
This editor is mainly for doing in-place Regular Expression search and replace operations, with one-click Undo for the times when it takes multiple attempts to get it right.
It also provides some one-click functions that I do often and some other functions just because they were possible.
It's not intended as a full-featured text editor, but as a way to do common useful transformations of blocks or snippets of text with a single click. As shown in the example below, it's useful for building batch files or bash scripts based on data in a list. It allows doing Perl or sed-like text transformations without the need for separate input/output files or STDIN/STDOUT piping and with the ability to quickly Undo and try again.
I needed to execute the same two commands on about 80 files. To avoid repetitive typing, I first listed the files in Windows Command Prompt:
C:\TEMP>dir /b *.bas BARGRAPH.BAS PRINMAZE.BAS
Then I ran a RegExp search and replace. With none of the optional regex flags checked, the expression in the Find box captures all the text on each line into the numbered variable $1, and the Replacement line supplies the text of the commands with the $1 filenames embedded where needed:
Find Regexp: (.*)
LOAD "BARGRAPH.BAS" SAVE "BARGRAPH.BAS",A LOAD "PRINMAZE.BAS" SAVE "PRINMAZE.BAS",A and about 160 more lines that I didn't have to type manually
1) RegExp Flags
2) "Lines" are determined by the presence of newline characters. The editor window wraps text to fit, so what looks like the end of a line on your screen might not be the end of a physical line. In Firefox 4, you can expand the editor window to fit your screen size.
3) As shown in the Example, the Replacement box can contain the standard backreference variables $1-$9, referring to text captured by parenthesized expressions in the Find box. The numbers correspond to the order in which the opening parentheses are encountered going left to right. You can use the RegexExec button to preview how the parenthesized expressions will be matched.
4) Sentence Case converts the entire string to lower case, then capitalizes the first letter of each paragraph, the first letter following a period and space, and each instance of the word "I". If the starting text contains proper nouns or other capitalized words, Sentence Case doesn't preserve them, so it can create more work than it saves.
5) ToCharCodes produces a comma-separated list of the decimal ASCII character codes corresponding to the entered characters: "ABC" becomes 65,66,67.
6) FromCharCodes converts a list of decimal ASCII character codes to plain text. The delimiters do not have to be commas. Any sequence of non-digits is treated as a delimiter.
7) UnescapeChars recognizes several decimal and hexadecimal formats in which ASCII characters can be encoded, (%HH &#xHH \xHH &#DD) plus a few HTML entity encodings (" & ' < > ), and converts the encoded characters to plain ASCII text, even if they are intermingled with ordinary non-encoded text.
9) Grep separates the input text lines into two groups. It puts lines containing a match of Find Regexp in the Regex Matches output box (the lower box), and leaves behind the lines not containing any match in the original input box (the upper box). Grep only operates on whole lines of the input text. It ignores the g and m flag settings, but pays attention to whether i is checked or not.
10) The labels Find Regexp and Replacement are buttons. Click to clear. Double-click clears both. Regex flags is a button. Click to clear all, Double-click to check all.
I developed and tested the editor with Firefox 4.0.1 and Internet Explorer 8. Bug reports, feature suggestions, and questions are welcome in the Forum.
Copyright ©2012 Steven Whitney. Last modified Sun 07/29/2012 11:56:38 -0700.