nuance has asked for the wisdom of the Perl Monks concerning the following question:
I have now got stuck with the a regulart expression, it does not do what I expected and i can't figure out why. The expression is
I thought it should match anything that is not a backslash, followed by a backslash, followed by zero or an even number of backslashes all at the end of a string. It doesn't seem to work, I've included the script I had it as a part of, maybe someone can tell me why it doesn't work./[^\\]\\((\\)+\1)*$/
Thanks
#!/usr/bin/perl -w use strict; my @split; my $var; # the original string that I want to split my $tosplit = q(a=1&b=2\&3&c=4\\\\\&d=5); # print out the string to confirm how many backslashes have been left # by the quote statement print $tosplit . "\n\n"; # Split the string on the ampersand my @temp = split /&/, $tosplit; # I thought this should have joined any two strings that were # previously separated by an odd number of backslashes at the # end of a string. while ($_ = shift @temp) { $_ .= ("&" . shift @temp) and redo if /[^\\]\\((\\)+\1)*$/; push @split, $_; }; foreach $var (@split) {print "$var" . "\n"};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Backslashes in regular expressions
by perlmonkey (Hermit) on May 08, 2000 at 00:19 UTC | |
by nuance (Hermit) on May 08, 2000 at 01:55 UTC | |
by perlmonkey (Hermit) on May 08, 2000 at 06:43 UTC | |
by nuance (Hermit) on May 08, 2000 at 14:03 UTC |