What are regular expressions for?
Regular expressions are used whenever a task requires pattern matching:
- search engines
- protein analysis (bioinformatics)
- search and replace in text editors
- text processing utilities such as
sedandawk
Many programming languages provide various regular expression capabiltiies. Lexical analysers in compilers also use regular expressions.
Finite representation of languages
Consider the following language:
Can we describe this infinite language with a finite pattern?
-
Strings in can start with any number (possibly none) of :
-
Then we have the first , it should be alone and followed by at least one :
-
Then any number (possibly none) of :
-
Then comes the second :
-
Then either:
- No more but can be any number (possible none) of .
- Or after some (possibly none) , there is a third somewhere, followed by any number (possibly none) .
This gives us:
Combining all of these together gives us: