Here is my two cents' worth. I am not sure if it is what you mean. I have made the regexes deliberately somewhat convoluted :)

#! /usr/bin/perl -w use warnings; use diagnostics; use strict; eval { action() }; if ($@) { print "error:\n$@\n"; } sub action { my @a = split(/\n/,<<'ENDTEXT'); This is the text we will search through. Normally you'd have some other source like a file. Every line here becomes an element in array @a. ENDTEXT my $rregexes = get_regexes(); # get patterns my @compiled = map qr/$_/ix, @$rregexes; # pre-compile them, # case insensitive print "We got ". @$rregexes ." regexes to test:\n"; # show regexes: for (my $i=0;$i< @$rregexes ;$i++) { print "--------\nregex $i:\n--------\n"; print $rregexes->[$i]; } print "\nHere we go into matching loop:\n"; for (my $i=0;$i<@a;$i++) { for (my $j=0;$j<@compiled;$j++) { if ($a[$i] =~ /$compiled[$j]/) { print "$j match: ".sprintf('%-50s',$a[$i])."<== matched\n"; } else { print "$j no match: ".sprintf('%-50s',$a[$i])."\n"; } } } } sub get_regexes { # # Could also read these from config files! # my @regexes = (); my $i = -1; $regexes[++$i] =<<'REGEXTEXT'; ^ # beginning of string .* # any number of chars normally # .* # $ # end REGEXTEXT $regexes[++$i] =<<'REGEXTEXT'; ^ # beginning of string .* # any number of chars here # .* # element # .* # $ # end REGEXTEXT return \@regexes; }

In reply to Re: User configurable regex by erix
in thread User configurable regex by MiggyMan

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.