>First, [^"]* doesn't suppress backtracking.

In quoted something case like "", <html>, sometimes I saw negator was used as if to supress backtracking.

$a=q("aaa" and "bbb"); $a =~ s/".*"/test/g; print "back tracked #$a#\n"; $a=q("aaa" and "bbb"); $a=~ s/"[^"]*"/test/g; print "with negator #$a#\n"; $a=q("aaa" and "bbb"); $a=~ s/".*?"/test/g; print "with backtrack supress #$a#\n";
Do you mean [^"]* backtracks internally?

My question (what I don't get) is 'Where the double quote gone when this regex matches againt To:<marmot@furrytorium.com> ?' Below is my simplified further example.

$text = <<'EOT'; Message-ID: <ODM2bWFpbGVyLmRpZWJlYS40MjYyNjE2LjEyOTU1NDE2MTg=@out-p-h. +customernews.net> To: "Angie Morestead" <marmot@furrytorium.com> EOT my @tos=( q(To:"Furry Marmot" <marmot@furrytorium.com>) ,q(To:"Mr.Furry Marmot" <marmot@furrytorium.com>) ,q(To:"pharmacy" <marmot@furrytorium.com>) ,q(To:<marmot@furrytorium.com>) ,q(To:<test@furrytorium.com>) ); foreach my $to( @tos){ $text =~ s/To:.*/$to/; print "$text\n"; ###two condition version if ($text =~ m{ ^(?:From|To): \s* ".*Furry\s{1}Marmot" \s* <marmot\@furrytorium\.com> }mx || $text =~ m{ ^(?:From|To): \s* <marmot\@furrytorium\.com> }mx ) { print "### with two cond, ok, matched=#$&#\n"; }else { print "### with two cond, ng\n"; } ###one condition if ($text =~ m{ ^(?:From|To): #From: or To: \s* " #<---here Where are you gone? (?!.*Furry\s+Marmot) # [^"]* # " # \s+ # <marmot\@furrytorium\.com> }mx ){ print "### Spam!! ,matched=#$&#\n"; }else { print "### not Spam!!\n"; } print "\n\n"; }

And why "To:<test@furrytorium.com>" is not Spam...? I think I'am missing something... Anyway I should print out prelretut. thanks.


In reply to Re^6: Looking for ideas on how to optimize this specialized grep by remiah
in thread Looking for ideas on how to optimize this specialized grep by afresh1

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.