Regular expressions are a grammatical notation for defining string syntax, but without general recursion. See previous notes on Nonrecursive Syntax: The Regular Expression Metalanguage.
Regular expressions are widely supported in modern programming languages and tools.
java.util.regex package.
flex can generate very efficient
scanning tools.
Here we summarize the main features common to most regular expression facilities.
($hrs, $min, $sec) =
$timeStr =~ m/([0-9]+):([0-5][0-9]):([0-5][0-9])/;
could select three subfields from $timeStr and assign them to
appropriate variables. Here the Perl "m//" syntax is used to specify
the regular expression for matching. Substring selection may
also be used for matching and replacement with the "s///" syntax.
For example:
$timeStr =~
s/([0-9]+):([0-5][0-9]):([0-5][0-9])/\2 min., \3 sec. after \1/;
This is an operation that might change $timeStr from "4:25:18" to
"25 min., 18 sec. after 4".
In this example, the notation \1 stands for the first matched
substring, \2 the second matched substring and so on.
In other Unix tools, grouping uses "\(" and "\)" instead of "(" and ")". In those tools "(" and ")" simply stand for themselves. For example, in the "ex" or "vi" editors, a match and replace command might be:
s/\([0-9]+\):\([0-5][0-9]\):\([0-5][0-9]\)/\2 min., \3 sec. after \1/;