How to order regular expression alternatives to get longest match? : <p>I have a number of regular expressions <code>regex1</code>, <code>regex2</code>, ..., <code>regexN</code> combined into a single regex as <code>regex1|regex2|...|regexN</code>. I would like to reorder the component expressions so that the combined expression gives the longest possible match at the beginning of a given string.</p>

<p>I believe this means reordering the regular expressions such that "if <code>regexK</code> matches a prefix of <code>regexL</code>, then <code>L &lt; K</code>". If this is correct, is it possible to find out, in general, whether <code>regexK</code> can match a prefix of <code>regexL</code>?</p>
