First, notice that the $ anchor in a regex will ignore the line ending if it even exists.#!/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('
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |