Sorry, thought it sounded simpler than it was. :)

However I did do something similar myself not too long ago for a program I wrote. This was for a regular expression tutor I wrote ( which I hope to post to craft as soon as I iron out one blasted bug ) so hopefully this will prove useful to you.

=head2 If we've had a regular expression with grouping, we need to sho +w the matches we made there too. Unless we count the number of matchi +ng parens, which could get odd if there was a match looking for '( +' and ')', we run a simple counter and check if the match variable exists. + If it does, we print it out. If no parenthesis are used, $match_resul +ts holds our match. =cut {eval "\@matches = (\$user_text =~ $regex); \$match_results .= +\$&;"; $match_results .= "\n"; $match_results .= " Variables:\n"if defined($matches[$i]) +; for (my $i = 1; $i <= @matches; $i++) { my $found = $matches[$i - 1]; $match_results .= " \$$i:$found \n" if defined($matc +hes[$i]); } } # end eval block } # end if substr eq 'm'

This does encompass multiple matches on an m//. The s// and tr// I did like: eval "\$match_results =~ $regex

Of course I did have the help of some here to pull this stunt off :)

Good luck!


In reply to Re: Re: Re: Regexes loaded from file by Popcorn Dave
in thread Regexes loaded from file by arunhorne

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.