AUTOMATA
(Regular Expression)
Prepared by: Genevieve C. Oca
Common
Operators for
Regular
Operators
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
\, escape
Converts operators to text.
Examples:
\? rule for a question mark
\* rule for an asterisk
* same as above
a\+\+ same as a++
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
. Arbitrary character
Stands for any character.
Examples:
. This will accept one character
.oca. This will accept one character
followed by oca and another character
again. Example: vocal, local, etc.
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
[ ] character class
A set of characters that can match
a single input character.
All operators become text inside a
character class except the
following:
- (dash) indicates range
^ (caret) indicates complement
\ (backslash) escapes within
character class
[ ] character class
Examples:
[a-zA-Z] rule for a single letter
[0-9] rule for a single digit
[^a-zA-Z] anything except a letter
[\n\t] a carriage return or a tab
If the dash sign needs to be a part of a character
class, it needs to be at the beginning or at the end .
[-+] rule for a negative or positive sign
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
? Optional character
Zero or one occurrence of the
preceding expression.
[-+]? optional negative or positive
sign
Colou?r can match color or colour
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
*, + repeated expression
* : zero or more occurrences of
the preceding expression.
+ : one or more occurrences of
the preceding expression.
[a-zA-Z_][a-zA-Z0-9_]*
-rule for an identifier
[-+]?[0-9]+
-rule for a (signed) integer
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
| altrnative
Any of the alternative expressions
will be recognized.
Example:
0|1|2|3|4|5|6|7|8|9 a digit, the
hard way
oca|chu|meow can match oca or
chu or meow
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
^ beginning of line
The expression following this
operator will only be matched if
found after a newline character
or at the beginning of the input
stream.
Example:
^(ab|cd) ab or cd will be
recognized only if after \n
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
$ end of line
If the expression is ended by this
operator, then the expression will
be matched only if found at the
end of a line.
Example:
(ab|cd)$ ab or cd will be
recognized only if before \n
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
/ trailing context
The format is: Expr1/Expr2. This
means that Expr1 will be
recognized only if found before
Expr2. Expr2 will not be
consumed.
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
{}
Allows different kinds of repetition.
Example:
a{1,5} the same as (a|aa|aaa|aaaa|
aaaa)
a{1,} the same as a+, one or more
repetitions of a
a{2,} two (2) or more repetitions of a
a{5} exactly five (5) repetitions of a
Basic operators
. Arbitrary
\, escape
character
? Optional
[] character class
character
*, + repeated
expression
| alternative
^ beginning of line
$ end of line
/ trailing context
{} repetitions
^^,
I can do all things through
Christ
Who strengthens me
-Philippians 4:13