Want to see how a regular expression is compiled? Perl can tell you!

perldebug:

Debugging regular expressions There are two ways to enable debugging output for regular expressions. If your perl is compiled with -DDEBUGGING, you may use the -Dr flag on the command line. Otherwise, one can use re 'debug', which has effects both at compile time, and at run time (and is not lexically scoped). [snip; read the details in the perldebug documentation.]
The really nice part is that, unlike most of the low-level debugging features, you don't need a DEBUGGING build of Perl to debug your regular expressions.
#!perl -c use re 'debug'; /at/||/bt/||/ct/||/dt/||/et/||/ft/||/ght/; /at|bt|ct|dt|et|ft|ght/; /[abcdef]t|ght/; /(?:[abcdef]|gh)t/; /(?:a|b|c|d|e|f|gt)t/; __END__
Here's the output from 5.005_03, reformatted for a little extra clarity:
/at/||/bt/||/ct/||/dt/||/et/||/ft/||/ght/; compiling RE `at' size 3 first at 1 1: EXACT <at>(3) 3: END(0) anchored `at' at 0 (checking anchored isall) minlen 2 compiling RE `bt' size 3 first at 1 1: EXACT <bt>(3) 3: END(0) anchored `bt' at 0 (checking anchored isall) minlen 2 compiling RE `ct' size 3 first at 1 1: EXACT <ct>(3) 3: END(0) anchored `ct' at 0 (checking anchored isall) minlen 2 compiling RE `dt' size 3 first at 1 1: EXACT <dt>(3) 3: END(0) anchored `dt' at 0 (checking anchored isall) minlen 2 compiling RE `et' size 3 first at 1 1: EXACT <et>(3) 3: END(0) anchored `et' at 0 (checking anchored isall) minlen 2 compiling RE `ft' size 3 first at 1 1: EXACT <ft>(3) 3: END(0) anchored `ft' at 0 (checking anchored isall) minlen 2 compiling RE `ght' size 4 first at 1 1: EXACT <ght>(4) 4: END(0) anchored `ght' at 0 (checking anchored isall) minlen 3 /at|bt|ct|dt|et|ft|ght/; compiling RE `at|bt|ct|dt|et|ft|ght' size 23 1: BRANCH(4) 2: EXACT <at>(23) 4: BRANCH(7) 5: EXACT <bt>(23) 7: BRANCH(10) 8: EXACT <ct>(23) 10: BRANCH(13) 11: EXACT <dt>(23) 13: BRANCH(16) 14: EXACT <et>(23) 16: BRANCH(19) 17: EXACT <ft>(23) 19: BRANCH(23) 20: EXACT <ght>(23) 23: END(0) minlen 2 /[abcdef]t|ght/; compiling RE `[abcdef]t|ght' size 18 1: BRANCH(14) 2: ANYOF(12) 12: EXACT <t>(18) 14: BRANCH(18) 15: EXACT <ght>(18) 18: END(0) minlen 2 /(?:[abcdef]|gh)t/; compiling RE `(?:[abcdef]|gh)t' size 18 1: BRANCH(12) 2: ANYOF(16) 12: BRANCH(15) 13: EXACT <gh>(16) 15: TAIL(16) 16: EXACT <t>(18) 18: END(0) minlen 2 /(?:a|b|c|d|e|f|gt)t/; compiling RE `(?:a|b|c|d|e|f|gt)t' size 25 1: BRANCH(4) 2: EXACT <a>(23) 4: BRANCH(7) 5: EXACT <b>(23) 7: BRANCH(10) 8: EXACT <c>(23) 10: BRANCH(13) 11: EXACT <d>(23) 13: BRANCH(16) 14: EXACT <e>(23) 16: BRANCH(19) 17: EXACT <f>(23) 19: BRANCH(22) 20: EXACT <gt>(23) 22: TAIL(23) 23: EXACT <t>(25) 25: END(0) minlen 2
Of course, that's just how the regular expressions are compiled; to see how the regexes are matched -- which is where the optimizer really comes into play -- give the regexes something to match against and watch the output at runtime!

In reply to Re: Regexp Speed Concerns by chipmunk
in thread Regexp Speed Concerns by tadman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.