Re: POSIX and PCRE help
| From: | OrangeHairedBoy | Date: | Sat, 16 Nov 2002 15:16:51 +0000 |
| Subject: | Re: POSIX and PCRE help | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-124722@lists.php.net to get a copy of this message | ||
Aaron,
Thanks for the advise, but I'm got a problem. If I first split it up by /;/,
how do I catch it if there's a semi-colon inside a string?
Lewis
"Aaron" <aaron_ott@hotmail.com> wrote in message
news:20021116091753.85663.qmail@pb1.pair.com...
> Lewis,
>
> First I would look at breaking out the tags:
>
> // User: JohnDoe; age=32; nickname="Billy 'the' Kid";
haircolor=orange;
>
> $string = 'User: JohnDoe; age=32; nickname="Billy \'the\' Kid";
> haircolor=orange;';
> $stringArray = preg_split('/;/', $string, -1, PREG_SPLIT_NO_EMPTY);
>
> Then split by the = or :
>
> // split by = or :
>
> foreach ($stringArray as $item) {
> list($tag, $element) = preg_split('/\:|\=/', $item, 1,
> PREG_SPLIT_NO_EMPTY);
> echo "$tag => $element<br />";
> }
>
> -aaron
>
> "Orangehairedboy" <me@orangehairedboy.com> wrote in message
> news:20021116071951.35473.qmail@pb1.pair.com...
> > I am trying to learn more about regular expressions as I haven't used
them
> > much in the past. I am working with email, and I'm looking for a way to
> > split the following expression up:
> >
> > Content-Type: text/plain; boundary="whatever";
> >
> > Using "/^(\S+)\:\s*(.+)$/iU" I can split it into:
> >
> > [Content-Type] and [text/plain; boundary="whatever";]
> >
> > Problem is, it might have different tags. Here's a sketch of the whole
> > thing:
> >
> > [Header Name a-zA-Z0-9] [\s*] [:] [\s*] [ Header value a-zA-Z0-9/_ ]
[\s*]
> > [;] [ unlimited repeating pattern of ( [Property Name a-zA-Z0-9] [\s*]
[=]
> > [\s*] ( string optionally surrounded by quotes - but necessary if value
> has
> > spaces - but can't include quotes ) [\s*] [;] ) ]
> >
> > So, if I had:
> >
> > User: JohnDoe; age=32; nickname="Billy 'the' Kid"; haircolor=orange;
> >
> > I would need:
> >
> > User - "JohnDoe" - age - "32" - nickname - "Billy 'the'
> > Kid" -
haircolor -
> > "orange"
> >
> > in the outputted array. I have no idea how to do repeating patterns like
> > this...maybe I'm making this too complex?
> >
> > Thanks for your help!
> >
> > Lewis
> >
> >
>
>