Searching with Regular Expressions

The Editor takes advantage of the regular expressions feature of editors such as vi or ed. Regular expressions let you expand the search process from exact matches to pattern matches. A “wild card” character is a simple example of a regular expression, allowing you to find a word in both singular and plural form. Regular expressions can be used in the Editor to search all typed characters, including control characters, sets or ranges of characters, and characters at a certain position in a line.

This appendix provides, as an introduction to using regular expressions, some examples that might be helpful in editing Lawson programs. It does not provide a detailed reference or set of instructions to all regular expressions, because each operating system has a slightly different set of legal expressions. You should become familiar with the use of regular expressions in your computing environment.

The following table shows valid symbols and their associated meanings.

Symbol Explanation
Used within brackets, the hyphen signifies a character range. For example, [a-z] is equivalent to [abcd...xyz]. The – can represent itself only if used as the first or last character. For example, the character class expression [ ]–] matches the characters ] and –.
\t Matches a tab.
^ Matches the beginning of a line. Must appear as the first character in the search string.
$ Matches the end of the line. Must appear as the last character in the search string.
. Matches any arbitrary character(s). For example, th.se matches these, those, or both sets.
* A regular expression followed by * means find a match zero or more times. For example, if you have the string 5678 in your file, [0-9] finds 5 first, then 6, then 7, and finally 8. The expression [0-9][0-9]* finds 5678 first, then 678, then 78, then 8.
+ A regular expression followed by + means find a match one or more times. For example, [0-9]+ is equivalent to [0-9][0-9]*, and finds 5678 first, then 678, then 78, then 8.

Because all of the above defined symbols are special characters, they must be escaped to be used as themselves.