The comments so far have to do with whether or not there is a "\n" at the end of tail.
Here are some ways to make your regex insensitive to that:
#!/usr/bin/perl use strict; use warnings; # modified code from [Grandfather] my $tail = ".D(next_out_en), .CP(n16), .CDN(n48), .Q(\n"; my $tail2 = ".D(next_out_en), .CP(n16), .CDN(n48), .Q("; print "MatchedA: \$1 '$1', \$2: '$2', \$3: '$3'\n" if $tail =~ /^\s*(.+)\s+\.\s*CP\s*\(\s*(\S+)\s*\)\s*\,\s+(.+)\s*$/ +i; print "MatchedB: \$1 '$1', \$2: '$2', \$3: '$3'\n" if $tail2 =~ /^\s*(.+)\s+\.\s*CP\s*\(\s*(\S+)\s*\)\s*\,\s+(.+)\s*$ +/i; print "MatchedC: \$1 '$1', \$2: '$2', \$3: '$3'\n" if $tail =~ /^\s*(.+)\s+\.\s*CP\s*\(\s*(\S+)\s*\)\s*\,\s+(.+)\s*/i +; __END__ Prints: MatchedA: $1 '.D(next_out_en),', $2: 'n16', $3: '.CDN(n48), .Q(' MatchedB: $1 '.D(next_out_en),', $2: 'n16', $3: '.CDN(n48), .Q(' MatchedC: $1 '.D(next_out_en),', $2: 'n16', $3: '.CDN(n48), .Q('
First, notice that the $ anchor in a regex will ignore the line ending if it even exists.

Second, notice that since "\n" is one of the white space characters. You can simply remove "\n" from the regex and it won't matter whether the "\n" character(s)are there or not. This is shown as option C.


In reply to Re: pattern matching by Marshall
in thread pattern matching by simon2016

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.