On 5/9/07, Ronald J Kimball <[EMAIL PROTECTED]> wrote:
>
> On Wed, May 09, 2007 at 12:54:49PM -0400, Simon R wrote:
> > OK... I've been toying with this for a day now and it's time to set the
> > experts loose. I need to be able to split a string of the form
> >
> > foo,bar',name=simon,age=99
> >
> >  into its constituent parts (comma is the delimeter). So far so good and
> > very simple using split().  However, I also need to be able to handle
> the
> > case where there may be commas in a phrase enclosed by quote marks, in
> which
> > case we should NOT split on those commas;
> >
> > e.g.
> >
> > foo,bar,names="charlie,john,ann",ages='20,30,40' must be split to
> >
> > foo
> > bar
> > names="charlie,john,ann"
> > ages='20,30,40'
> >
> > Can anyone come up with a single regexp that I can use in a call to
> split()
> > that will handle this case, or another equally elegant solution ?
> >
>
> Try this:
>
> @parts = $string =~ /((?:"[^"]*"|'[^']*'|[^,])+)/g;


works like a charm !

thanks for the help

-Simon


(Just make sure your quote characters are properly balanced!)
>
> Ronald
>
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to