Every regular expression contains a pattern, which is used to match
the regular expression against a string.
Within a pattern, all characters except ., |, (, ), [, {, +, \,
^, $, *, and ? match themselves.
showRE('kangaroo', /angar/)
|
� |
k<<angar>>oo
|
showRE('!@%&-_=+', /%&/)
|
� |
!@<<%&>>-_=+
|
If you want to match one of these special characters literally,
precede it with a backslash.
This explains part of the pattern we used
to split the song line,
/\s*\|\s*/
. The
\|
means
``match a vertical bar.'' Without the backslash, the ``
|
'' would have
meant
alternation (which we'll describe later).
showRE('yes | no', /\|/)
|
� |
yes <<|>> no
|
showRE('yes (no)', /\(no\)/)
|
� |
yes <<(no)>>
|
showRE('are you sure?', /e\?/)
|
� |
are you sur<<e?>>
|
A backslash followed by an alphanumeric character is used to introduce
a special match construct, which we'll cover later. In addition, a
regular expression may contain
#{...}
expression
substitutions.