Thoughts, quotes and thoughts about regex

thibaultduponchelle

Tib

Posted on February 22, 2021

Thoughts, quotes and thoughts about regex

Regex

"Regex" is the small name of Regular expressions

Regex are one of the superpowers 💪 of Perl
Perl <3 Regex

It's a productivity superpower the same way knowing command line shortcuts and mastering vim.

Regex could become one of your programmer superpowers also if you decide to.
True power

But "regex" have also a nefarious reputation because they are hard, error-prone and misused.
100

Damian Conway is a master of regular expressions but you can sometimes feel the pain in his mouth when he discusses regex
Pain

Or even
Misery

But on a more positive note, Damian said
WrongButGoodEnough

It could be strange to advocate a wrong thing but sometimes you just don't need more than a one shot program, and for me it would be dumb (or irresponsible) to spend more time than needed just "for the sake of correctness".
David Goodenough

I know it's not really the hype of these days where over engineering is better perceived than KISS principles (I exaggerate just a little) but it is pragmatism.

Regex are bad

Regex are bad, everybody knows, and here is the very famous SO answer "You can't parse [X]HTML with regex" about that 😀
Idiot

Are they really?

Some people have played the "devil's advocate" and came with regex for XML like this great answer from Tom Christiansen where he used regex to tokenize then Perl to parse.

But even Tom Christiansen said
Should

Seems also like PCRE are more than simple regular grammars but actually I can't say if mathematically Perl regex can or can't parse XML, regular expression page on wikipedia says that
Regular not regular

Another interesting old link on this topic is REX. The abstract of it is

The syntax of XML is simple enough that it is possible to parse an XML document into a list of its markup and text items using a single regular expression. Such a shallow parse of an XML document can be very useful for the construction of a variety of lightweight XML processing tools

(I do not quoted this one on a picture since I'm too afraid to awake Cthulhu)

Then what are regex recommended for

While use of complex regex are subject to discussions, there are perfect and obvious use cases for regex:

  • Validation of input
  • Cleaning of input
  • Restructuring of input
  • Looking for substrings within input

Folklore

I discussed about WrongButGoodEnough regex that help you save the world on a Friday evening:
Save

But writing regex is hard to master and you probably don't
Trial

One solution is to leave your cat typing the regex for you!
Cat regex

Perl folks are crazy about regex

I wanted to finish with this crazy fact, fasten your seat belts.

Perl folks are really serious about regex
Serious

This is mad.

💖 💪 🙅 🚩
thibaultduponchelle
Tib

Posted on February 22, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related