Re: preg_match and delimited strings



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

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);
}

It's a bitch for sure, isn't the wonderfull function fgetcsv() maybe
applicable in this case?

Grtz,
--
Rik Wasmus


.



Relevant Pages

  • Re: How to pass string in command line argument.
    ... Perl Pra wrote: ... i have perl script that searches given string (the string should be passed ... The string should be sent to the script with double quotes attached to it ...
    (perl.beginners)
  • Re: How to pass string in command line argument.
    ... >>> my perl script is something like this ... >>> just a straight string is geeting passed ... >>> but i need to send the entire string including double quotes to the ...
    (perl.beginners)
  • Re: Comments requested: brief summary of Perl
    ... >of Perl. ... When converting a string to a number, only the characters up to the first nonnumeric ... | Assignment is done with the = sign, as seen above, and you can use an assignment statement ... Within single quotes, the only ...
    (comp.lang.perl.misc)
  • Re: oddness in quotes (PerlMagick)
    ... I thought Perl did not differ between single and ... m> double quotes, as long as used consistently in a string. ... have you ever used interpolation in a perl ...
    (comp.lang.perl.misc)
  • Re: What is @
    ... Only for strings inside of double quotes within a Perl script. ... Perl will look for variables in the string and replace them with the ... It will try to replace @isp with the contents of an array named @isp. ...
    (comp.lang.perl.misc)