Hello Louis,

>my $a = /^dat.*\n      #match 1st line
>       (?s)            #turn on . matching any char
>       (.*?3)/x;       #should match data 2 and 3
>print 'result: ',$a,', $1=',$1||'no match',"\n";
>1;
>__END__
>
>result: 1, $1=head 3
>
>I thought that '^dat.*\n' would match only the 1st line 'data 1', because '.' doesn't 
>match a new line.
>
>Then '(?s)' should make '.' match any char, including new line.
>Then '(.*?3)' should match lines 'data 2' and 'data 3'.

I think here is your misinterpretation.
Specifying (?s) within a regex is the same as putting
it at the end, i.e. /regex/s. That's why (?s) changes \n interpretation
fully in your example. I would split the task in two or go through
the string line by line.


HTH,
Axel

Reply via email to