Regular expressions are usually surrounded by / slashes. It is done in order to keep the 'switches' separate from the regular expression (the match text).
In PERL, the most common regex commands were like this:
m/(regex match here)/(switches)
and
s/(regex match here)/(substitute text here)/(switches)
Here are some examples of regexes:
alias df.check {
var %date.fmt = $1-
if ($regex(date,%date.fmt,/(^\s*$|d{5,}|m{5,}|y{5,}|(?<!y)y{3}(?!y)|o{3,}|(?<!o)o(?!o)|(?:[^d]|d{3,}|^)oo|[^dmoy -/\\])/)) echo 4 -a Invalid format: $regml(date,1)
else echo 3 -a Valid format
}
alias tf.check {
var %time.fmt = $1-
if ($regex(time,%time.fmt,/(^\s*$|[hH]{3,}|hH|Hh|n{3,}|s{3,}|[tT]{3,}|tT|Tt|[^z]{4,}|[^hHnstTz :-])/)) echo 4 -a Invalid format: $regml(time,1)
else echo 3 -a Valid format
}
The above code is used to determine if date/time formats (used in $asctime) are valid.
Looking at this code:
/(^\s*$|[hH]{3,}|hH|Hh|n{3,}|s{3,}|[tT]{3,}|tT|Tt|[^z{4,}|[^hHnstTz :-])/
It is broken down like this:
[1]: A numbered capture group. [^\s*$|[hH]{3,}|hH|Hh|n{3,}|s{3,}|[tT]{3,}|tT|Tt|[^z]{4,}|[^hHnstTz :-]]
Select from 11 alternatives
^\s*$
Beginning of line or string
Whitespace, any number of repetitions
End of line or string
Any character in this class: [hH], at least 3 repetitions
hH
Hh
n, at least 3 repetitionss, at least 3 repetitions
Any character in this class: [tT], at least 3 repetitions
tT
Tt
Any character other than z, at least 4 repetitions
Any character that is not in this class: [hHnstTz :-]
/
The way the code is written, if the regex matches, then the date/time format is INvalid.
There is no shortage of Regex tutorials or examples on the internet. The easiest way to learn is to read the tutorials and then try the examples. Then try your own regexes. Find some data that has a recognizable format, but also has parts that change (ex. time, date, etc) and then make a regex that will match it, even when the data changes.
-genius_at_work