Re: regexp appears to be faulty!?
| From: | Henry Grech-Cini | Date: | Tue, 24 Feb 2004 15:34:02 +0000 |
| Subject: | Re: regexp appears to be faulty!? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-178706@lists.php.net to get a copy of this message | ||
Thanks for that Mike,
I was getting lost.
Is there anyway to say
Any characters excluding the sequence </fieldset>
so I could do something like
/<fieldset([^>]*)>(.* whilst not <\/fieldset>)<\/fieldset>/i
Or alternatively is there a switch to say get the smallest sequence
Thanks
Henry
"Mike Ford" <M.Ford@leedsmet.ac.uk> wrote in message
news:0EEFC4D3CBE8A142868E396381B77A53D1255F@lis-exchange3.lmu.ac.uk...
> On 24 February 2004 12:40, Henry Grech-Cini wrote:
>
> > Hi All,
> >
> > function extractFieldsets($subject)
> > {
> > $regexp="/<fieldset([^>]*)>[^(<\/fieldset>)]*/i";
>
> This: [^(<\/fieldset>)]
> will match any *single* character except the ones listed -- i.e. any
character that isn't one of: ()<>/defilst
>
> So this: [^(<\/fieldset>)]*
> will match any run of characters that is not in that set.
>
> >
> > And it produced;
> >
> > (0)=
> > (0)=[<fieldset attribute="hello">con]
> > (1)=[<fieldset attribute="goodbye">goo]
> >
> > Why did it get three letters after the end of the "fieldset" tag????
>
> By coincidence, the 4th letter in each case is one of the set listed
above, and so ends the match: "t" in "content" and "d" in
"goodbye". If the
second example had ahppened to be, say, "au revoir", you'd have got 4
characters ("au r").
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@leedsmet.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
>