in reply to split on delimiter unless escaped
A regex for that is:
my $re = qr{ (?> # don't backtrack into this group !. # either the escape character, # followed by any other character | # or [^!;\n] # a character that is neither escape # nor split character )+ }x; while ($str =~ /($re)/g) { print "Chunk '$1'\n"; }
This technique is fairly general, and works for example for quoted strings, where the backslash can escape the quote character to not terminate the string.
You can read more about it in Mastering Regular Expressions by Jeffrey E.F. Friedl, a book I can warmly recommend.
Update: Added \n to the negated character class; mr_mischief pointed out that it is probably closer to the desired output that way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split on delimiter unless escaped
by ikegami (Patriarch) on Nov 09, 2010 at 22:54 UTC | |
by yrp001 (Initiate) on Nov 10, 2010 at 00:19 UTC | |
by ikegami (Patriarch) on Nov 10, 2010 at 01:10 UTC | |
|
Re^2: split on delimiter unless escaped
by yrp001 (Initiate) on Nov 09, 2010 at 22:21 UTC | |
by yrp001 (Initiate) on Nov 10, 2010 at 00:58 UTC |