Hi all, I tried to extract string from perl script, so I wrote following script:
5# matching string 6 # sting start with ' or ". 7 # assume string is on same line. 8 # 9 my $pattern = '(\"|\').*\1'; 10 my @array; 11 open (my $file, "<", "str"); 12 while (my $line = <$file>) {. 13 if($line =~ /$pattern/) { 14 push (@array, $&); 15 } 16 } 17 18 for (@array) { print "$_\n"; } the str sample file : ----------------------------------------------- 'okay i know now' "from time to time" 'let us go' this is awkward ------------------------------------------------ I would expect the output match three of them, however, it only matches: ------------------------------ 'okay i know now' "from time to time" ------------------------------- leaving 'let us go' unmatched. I don't know how to describe this problem, Can anyone help me with this ? Thanks in advance. --- Regards ! Alex Chiang