Regular expressions
Regular
Expressions are essentially patterns rather than specific strings that are used
with Find/Replace operations. There are many ways that regular expressions may
be used to streamline operations and enhance efficiency. We have listed below a
reference key for both UltraEdit-style and UNIX-style regular expressions as
well as some examples to demonstrate how regular expressions may be used in
UltraEdit.
- Simple String Matching
- Character Sets
- OR Expressions
- Deleting Blank Lines
- Reformatting with Tagged Expressions
Regular Expressions in UltraEdit | ||
---|---|---|
UltraEdit Symbol | UNIX Symbol | Function |
% | ^ | Matches/anchors the beginning of line. |
$ | $ | Matches/anchors the end of line. |
? | . | Matches any single character except a newline character. Does not match repeated newlines. |
* | Matches any number of occurrences of any character except newline. | |
+ | + | Matches one or more of the preceding character/expression. At least one occurrence of the character must be found. Does not match repeated newlines. |
++ | * | Matches the preceding character/expression zero or more times. Does not match repeated newlines. |
^ | \ | Indicates the next character has a special meaning. "n" on its own matches the character "n". "^n" (UE expressions) or "\n" (UNIX expressions) matches a linefeed or newline character. See examples below. |
[ ] | [ ] | Matches any single character or range in the brackets. |
[~xyz] | [^xyz] | A negative character set. Matches any characters NOT between brackets. |
^b | \f | Matches a page break/form feed character. |
^p | \p | Matches a newline (CR/LF) (paragraph) (DOS Files). |
^r | \r | Matches a newline (CR Only) (paragraph) (MAC Files). |
^n | \n | Matches a newline (LF Only) (paragraph) (UNIX Files). |
^t | \t | Matches a tab character. |
[0-9] | \d | Matches a digit character. |
[~0-9] | \D | Matches a non-digit character. |
[ ^t^b] | \s | Matches any white space including space, tab, form feed, etc., but not newline. |
[~ ^t^b] | \S | Matches any non-white space character but not newline. |
\v | Matches a vertical tab character. | |
[0-9a-z_] | \w | Matches any alphanumeric character including underscore. |
[~0-9a-z_] | \W | Matches any character except alphanumeric characters and underscore. |
(A|B) | Matches expression A OR B. | |
^ | \ | Overrides the following regular expression character. |
^(...^) | (...) | Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression. |
^1 | \1 | Numerical reference to tagged expressions. Text matched with tagged expressions may be used in Replace commands with this format. |
Note: ^ refers to the character '^' NOT Control Key + value. |
UltraEdit/UNIX Regular Expression Examples
Simple String Matching
Simple
string matching is probably the most basic form of regular expressions but can
allow you to quickly exploit different patterns so that you can search for more
than one string at a time rather than doing multiple Find operations.
UltraEdit RegExp:
Find
What: m?n
Matches: "man" and "men" but not "moon"
Find What: t*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").
Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
Matches: "man" and "men" but not "moon"
Find What: t*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").
Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
UNIX RegExp:
Find
What: m.n
Matches: "man" and "men" but not "moon"
Find What: t.*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").
Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
Matches: "man" and "men" but not "moon"
Find What: t.*t
Matches: "test", "tonight" and "tea time" (the "tea t" portion) but not "tea
time" (newline between "tea " and "time").
Find What: Te+st
Matches: "test", "teest", "teeeest", etc. but does not match "tst"
No comments:
Post a Comment