Big Tony <> wrote:
> Suppose I have two strings:
> $str1 = "abcd%efg";
> $str2 = "1234\%567";
I guess you haven't tried print()ing the value of $str2 at this point, huh?
> I would a regular expression that will return "abcd" from $str1 and
> "1234\%567" from $str2, i.e. if a "%" is encountered without being
> preceded by a "\" then ignore it and the remainder of the string, but
> if "\%" is encountered do nothing special and return it with the rest
> of the string.
None of your strings have a percent preceded by a backslash...
Anyway, you can use a "negative look-behind":
-------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
foreach ( 'abcd%efg', '1234\%567' ) {
print "string is '$_'\n";
# my( $stuff ) = /^(.*?)((?<!\\)%|$)/;
my( $stuff ) = /^(.*?) # bunch of chars until...
(
(?<!\\)% # ... a percent without preceding backslash
| # or
$ # end of string
)/sx;
print "stuff is '$stuff'\n";
}
-------------------------------------
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas