Security

txt2re: Regex Generator for People Who Hate Writing Regular Expressions

Regular expressions let you parse strings and text files quickly and cleanly—but only if you know the syntax and have some experience. Otherwise they turn into an eldritch nightmare, and prolonged exposure may well drive you insane.

The author of txt2re says, not without a hint of pride, that he’s always hated regexes and tried to avoid them whenever possible. That didn’t stop him, however, from creating a generator that, given a piece of text, helps you build a regular expression.

The string is automatically split into components—individual characters and substrings. You choose how you want them represented, and txt2re generates code in one of fifteen languages.

At first glance, txt2re lets you avoid writing regular expressions altogether. Unfortunately, there’s a major downside: the generator has no concept of elegant code, and the result is such a tangled mess that it’s hardly worth trying to make sense of. The author knows this perfectly well, but apparently doesn’t see it as a serious problem.

Maybe txt2re will teach you something new about regular expressions and how to use them without hacky workarounds (in that case you might also be interested in RegExr, which, conversely, helps deconstruct regexes). But much more likely, txt2re will make you hate regexes ten times more.

it? Share: