|
![](/i/fill.gif) |
Invisible <voi### [at] dev null> wrote:
> "Regular expressions are an extreme example of how concise a
> mini-language can be. Simple regular expressions express recognition
> behaviour that would otherwise have to be implemented with hundreds of
> lines of fussy, bug-prone code."
> Oh really? What what makes you think people don't use *libraries* for
> pattern recognition? :-P
I have always found it curious that you are infatuated with a
programming language known for the brevity of its programs, yet have
an almost irrational prejudice against regular expressions.
This is doubly curious because both Haskell and regular expressions
are based quite heavily on mathematical backgrounds, so it's yet another
thing in common with them.
You might not realize it, but regular expressions were not designed
randomly on a whim, but there are strong mathematical ideas behind the
syntax. One thing where this can be seen is that matching strings against
a regular expression can be done extremely efficiently: The matching can
be done one character at a time, without having to buffer any characters
nor ever jumping back in the string being matched. In other words, the
algorithm simply goes through the string from beginning to end, without
ever needing to make a jump backwards (or buffering characters), comparing
it to the regexp, and that's it.
The way this is done is that the regular expression is first converted
into a state machine, and this is where the mathematical background
jumps in: Regular expressions have been expressly designed so that they
can be converted into state machines, for this exact purpose.
Or looking at it from the opposite direction: Regular expressions are
a very convenient way of defining a state machine (for matching strings).
What otherwise would take tens if not even hundreds of lines of data (or
code) can be written with relatively short strings using a few special
characters, in an intuitive way.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |