#!/bin/perl -w use strict; while( ) { next if(/^\s*#/); # skip comments in DATA chomp; # split data into string to match and expected result(s) my( $string, @expected)= split /\s*=>\s*/; while( $string=~ m{" # the start delimiter ([^\\"]* # anything but the end of the string or the escape char (?:\\. # the escape char preceeding an escaped char (any char) [^\\"]* # anything but the end of the string or the escape char )*) # repeat "}gx) # the end delimiter { my $match= $1; my $expected= shift @expected; unless( $match eq $expected) { print "unexpected result line $.: found /$match/, expecting /$expected/\n"; } } } __DATA__ # string to match => expected results(s) toto "a string" tata => a string toto "a string" => a string toto "a string" tata => a string toto "a \" string" tata => a \" string toto "\" string" tata => \" string toto "a\"" tata => a\" toto "\"" tata => \" toto "\"\"" tata => \"\" toto "string 1" "string 2" tata => string 1 => string 2 toto "string 1 => toto "string 1" "string => string 1 toto "tata\\" tutu => tata\\ toto "tata\\\"" tutu => tata\\\" #### #!/bin/perl -w use strict; while( ) { chomp; next if(^\s*#); # skip comments # split the data into the string to match and the expected result(s) my( $string, @expected)= split /\s*=>\s*/; while( $string=~ m{/\* # the delimiter ([^*]* # anything but the beginning of the delimiter (?:\*(?!>/) # the beginning of the delimiter, not preceeding the rest of the delimiter # (?!>/) means "not before /, do not use the next char) [^/]* # anything but the beginning of the delimiter )*) # repeat \*/}gx) # the end of the delimiter { my $match= $1; my $expected= shift @expected || ''; unless( $match eq $expected) { print "unexpected result line $.: found /$match/, expecting /$expected/\n"; } } } __DATA__ # string => result(s) toto => toto /*foo*/ tata => foo /*foo*/ tata => foo toto /*foo*/ => foo toto /*foo*bar*/ => foo*bar toto /*foo**/ => foo* toto /**/ => /***/ => * /*/*/ => /