Regular expressions |
Regular expressions are a standard system for describing complex search patterns. It's the basis for much of the Perl language and is used in the grep utilities on Unix. The search pattern is made up of a combination of standard characters and special tags for allowing flexible matches. The following are the most important tags. If you want a literal match to one of the characters below, you need to "escape" it by prefixing with a \. The most common of these would be ( and ), which are a grouping operation in regular expressions, but also important characters in the RATS language.
^ |
matches the beginning of the line |
$ |
matches the end of the line |
\s |
matches "white space" |
. |
matches any character |
? |
quantifies preceding to match zero or one |
* |
quantifies preceding to match zero or more |
+ |
quantifies preceding to match one or more |
| |
allows for options |
(..) |
groups a subpattern (for instance (a|b) will match either a or b) |
[a-z]etc. |
matches any character in the range (typically either [a-z] for letters or [0-9] for digits. |
A simple example is ^%s*garch which will match an occurrence of the string "garch" that's the first non-blank information on a line. To break it down, ^ matches the beginning of line, %s* matches any number from 0 up of "white space", which means blanks or tabs, then garch means literally those five characters in order.
Copyright © 2025 Thomas A. Doan