Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    Convenient design and debugging of regular expressions under Linux

    10th October 2009

    redet-supported languagesRegular expressions (regexps) are powerful indeed. But debugging non-trivial regexps is a burden even if you understand how regexps work, and remember most (if not all) regexp syntax.

    Miscellaneous tools exist to ease this task. This post was inspired by redet’s comparison of regexp helper tools – it could be sufficient to read only that, if you’re going to try the mentioned tools yourself. Otherwise, read on.

    Kodos is an easy-to-use (but powerful enough) Python tool to verify regular expressions against sample user-provided strings. Available for both Linux and Windows. Generates ready-to-use Python regexp code.

    redet assumes some knowledge of REs. Unlike all the other helper tools, it has the widest code generation coverage – just go to “Tools->Save command information” to generate code (Python, Perl, C, grep – just to name a few of the 57 (!) languages/tools/editors supported). At the same time, redet does not depend on specific versions of all supported RE engines – instead, redet automatically tests for features in available versions.

    visual-regexp is similar to kodos in features.

    txt2regex is a regex wizard written in bash, capable of generating code for 24 languages/editors/programs (by default, these are enabled: perl, php, postgres, python, sed and vim). It is really simple and convenient, though some understanding of “groups” and “character ranges” is highly recommended.

    KRegExpEditor was a part of kde3-utils, and seems to be missing from current KDE 4.3. It is similar to kodos and visual-regexp in its philosophy and features.

    I would recommend using one of kodos/visual-regexp/kregexpeditor to quickly test or design your regular expression, then use redet to generate appropriate source code. As an alternative (and when working in a console), just use txt2regexp to generate the code you need.

    Tools I haven’t tried include regex coach and regexpviewer.

    Please also see this extensive list of regular expression and pattern-matching related software.


    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>