in reply to Splitting a comma-delimited string where a substring could contain commas
Here's a start, which doesn't use lookahead assertions. It works on your tests case, but I would throw more tests cases at it before putting it into production.
You have to understand a bit about backtracking to get how this works. It proceeds by trying to match, in this orderlocal $_ = "this, that, those, these (not enough, nope, never), there" +; while ( /(?:^|, )([^,]+\(.*?\)|[^,]+)/g ) { print $1, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Splitting a comma-delimited string where a substring could countain commas
by samtregar (Abbot) on May 03, 2002 at 19:09 UTC | |
by dws (Chancellor) on May 03, 2002 at 21:12 UTC | |
by I0 (Priest) on May 03, 2002 at 21:53 UTC |