I am trying to extract text from a string up to the next occurrence of a /, not counting slashes that occur within single quotes. For example
my $str="test 'a/b' c/ xxx /";
$str =~ /(.*?)\//;
print "$1\n";
gives
test 'a
whereas I would like to get:
test 'a/b' c
you can try this:
$str =~ /^((?>[^'\/]+|'[^']*')*)\//;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With