Re: Regex expert needed
On Mon, 2005-05-02 at 16:08 +0100, Alan Chandler wrote:
> For instance I want the parse this string
>
> Form = 'This is a bad bad thing, but not as bad as it would be if \"x = 5\",
> so thats it',Connection=5
>
> Into the strings
>
> Form
>
> =
>
> 'This is a bad bad thing, but not as bad as it would be if \"x=5\", so thats
> it'
>
> ,
>
> Connection
>
> =
>
> 5
>
> using the php preg_split() finction. So, I first want to find a regex that
> finds the commas I have split out (bit not the common in the quoted string,
> and then for each substring put that through another version of preg_split()
> which finds the = as delimeters. Again in the quoted string, I want to
> ignore the x=5 equal sign.
>
> I actually did this in the end by the brute force method of scanning the
> string character by character in php and using logic to determine where the
> boundaries are. Its just a regex ought to be much more elegant.
Would be yet harder still if you correct your grammar and put the
missing apostrophe in penultimate word, viz "that's"
--
Michael Bane
Atmospheric Physics Group
University of Manchester
Reply to: