preg_match and delimited strings



I have a string I'd like to have broken into parts using preg_match. I
used a regular expression from the Perl FAQ (http://perlfaq.cpan.org/):


push(@new, $+) while $text =~ m{
"([^\"\\]*(?:\\.[^\"\\]*)*)",? # groups the phrase inside the
quotes
| ([^,]+),?
| ,
}gx;

The idea is that it splits delimited strings respecting the quotes, for
example...

foo, bar, "foo, bar", bar
would end up as
-foo
-bar
-"foo, bar"
-bar

So obviously an explode wont work.

I cant figure out how to convert that piece of perl above into
preg_match. I've copied the string and escaped all the appropriate
charecters however it still wont divide the string show above
properly...

$str = "foo, bar, \"foo, bar\", bar";
$re = "\"([^\\\"\\\\]*(?:\\\\.[^\\\"\\\\]*)*)\",?| ([^,]+),?| ,";
if (preg_match($re, $str, $res)) {
print_r($res);
}

I have other strings that need parsing too (including ones with a
double encapsulator inside the string - eg. 'don''t touch that!'). But
I'm saving those for later.

.



Relevant Pages

  • Re: Technical problem
    ... Also if you want to watch an expert at work damping get Denis ... Bar 3: The high E on beat two is damped when the next beat is played ... by fingering the adjacent lower string so that the finger slightly ... When playing the D on beat 2 I lay my index finger across the ...
    (rec.music.classical.guitar)
  • Re: Technical problem
    ... Also if you want to watch an expert at work damping get Denis ... Bar 3: The high E on beat two is damped when the next beat is played ... by fingering the adjacent lower string so that the finger slightly ... When playing the D on beat 2 I lay my index finger across the ...
    (rec.music.classical.guitar)
  • Re: BWV 999
    ... bars and then the open D that starts bar 7 gives the time to shift ... I misread the fingering of the penultimate note; ... The shift cuts off the E on the second string. ... preserve the whole bar as a harmonic unit in which the notes can ring ...
    (rec.music.classical.guitar)
  • Re: BWV 999
    ... bars and then the open D that starts bar 7 gives the time to shift down. ... I misread the fingering of the penultimate note; I thought the 1 was a ... The shift cuts off the E on the second string. ...
    (rec.music.classical.guitar)
  • Re: BWV 999
    ... Pujol chose. ... bars and then the open D that starts bar 7 gives the time to shift down. ... The shift cuts off the E on the second string. ...
    (rec.music.classical.guitar)