Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write more maintainable regular expressions?
    text
    copied!<p>I have started to feel that using regular expressions decreases code maintainability. There is something evil about the terseness and power of regular expressions. Perl compounds this with side effects like default operators. </p> <p>I DO have a habit of documenting regular expressions with at least one sentence giving the basic intent and at least one example of what would match. </p> <p>Because regular expressions are built up I feel it is an absolute necessity to comment on the largest components of each element in the expression. Despite this even my own regular expressions have me scratching my head as though I am reading Klingon. </p> <p>Do you intentionally dumb down your regular expressions? Do you decompose possibly shorter and more powerful ones into simpler steps? I have given up on nesting regular expressions. Are there regular expression constructs that you avoid due to mainainability issues?</p> <p><strong>Do not let this example cloud the question.</strong></p> <p>If the following by <a href="http://regexlib.com/REDetails.aspx?regexp_id=113" rel="noreferrer">Michael Ash</a> had some sort of bug in it would you have any prospects of doing anything but throwing it away entirely?</p> <pre><code>^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[13-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$ </code></pre> <p>Per request the exact purpose can be found using Mr. Ash's link above.</p> <p><strong>Matches</strong> 01.1.02 | 11-30-2001 | 2/29/2000 </p> <p><strong>Non-Matches</strong> 02/29/01 | 13/01/2002 | 11/00/02 </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload