Derived CompositionsΒΆ
Elementary compositions enable the definition of more complex and more practical operations. A fixed number of concatenations of the same DFA may be manually written as:
RRRRRRRR
which matches if and only if there are eight adjacent lexemes matched by R.
The shorthand for n repeated concatenations is
- R{n}
With
nbeing an integer greater or equal zero, the expression matches exactlynconcatenations of lexemes matched byR.
- R{n,m}
With
nandmbeing integers greater or equal zero, the expression matchesntom(includingm) concatenations of lexemes matched byR. It is a shorthand for the union of allR{i}withiiterating fromntom.
In general, a restriction on the number of repetitions is accomplished with
ranges in { and } brackets. In practical applications, repetitions are
often restricted with respect to their number. While the Kleene closure also
matches the lexeme of zero length, the Kleene plus operation requires at
least one repetition to match.
- R+
The Kleene plus operation. It matches an arbitrary number of repetitions of what is matched by
Rbut not zero repetitions. It is a shorthand for the concatenation ofRandR*.
The minimum number of repetitions can also be restricted by integers greater than one.
- R{n,}
With
nbeing an integer greater or equal zero, matches an arbitrary number of repetitions of what is matched byRbut not less thannnumber of repetitions. It is a shorthand for the concatenation ofR{n}andR*.
Zero or one repetition are called optional expressions and their
syntax is the ? suffix.
- R?
Matches zero or one occurrence of what matches
R. It is a shortand for the union of\NothingandR.