in reply to Re^2: negative lookbehind and VERY strange capture
in thread negative lookbehind and VERY strange capture
Glad to hear you have a working solution. Might I also suggest that for test scripts like this you consider using one of the Test::* frameworks? They will help to highlight where your matches fail. Here's an example using the ubiquitous Test::More to show how simple it would be to integrate.
#!/usr/bin/perl use strict; use warnings; use Test::More; # Set up source strings (keys) and expected results (values) my %tests = ( '"abcd\\\\efgh"' => 'abcd\\\\efgh', '"abcd\\""' => 'abcd\\"', '"abcd\\"efgh"' => 'abcd\\"efgh', '"abcd\\\\\\"efgh"' => 'abcd\\\\\\"efgh', '"abcd\\\\i\\"efgh"' => 'abcd\\\\i\\"efgh', '"abcd\\\\"' => 'abcd\\\\' ); # Set the total number of tests to perform plan tests => 3 * keys %tests; while ( my ($test, $exp) = each %tests) { ok ($test =~ /^"((?:[^"\\]|\\["\\])+)"$/, "$test matches"); is ($1, $exp, "\$1 is $exp"); is ($2, undef, '$2 is undefined'); }
If any of the tests fail it is easier to spot than having to visually parse the script output. You can also run prove on the script to get just a summary which is even clearer.
If you write a lot of scripts like this, it is well worth becoming familiar with the wealth of testing modules available.
|
|---|