Re: regular expression help

From: Date: Thu, 25 Jan 2001 20:51:43 +0000
Subject: Re: regular expression help
Groups: php.general 
Request: Send a blank email to php-general+get-36698@lists.php.net to get a copy of this message
In article <005801c08668$e0459070$0201010a@shaggy>, "Jamie Burns" <jamie.burns@dynamicexpression.co.uk> wrote: I tried something like this and your examples worked: $str = "<tag element = \"value\" nextelement>"; if (eregi("=[[:space:]]*\"([^\"]+)|=[[:space:]]*([[:alnum:]]+)",$str,$regs)) { print("yes - ".$regs[1].":".$regs[2]."<br>\n"); } since the pattern has an 'or' (|), you have to look in either the second or the third element of the array you use to store values from the ereg. Jeff > can anyone help me figure out a regular expression to find the value of > a tag element? > > for example: > > <tag element="my value"> > <tag element=value> > <tag element="my value" nextelement> > <tag element=value nextelement> > <tag element = "my value"> > <tag element = value> > <tag element = "my value" nextelement> > <tag element = value nextelement> > > so in each of the above i need to find either "my value" or "value"... > > i tried this but it wont work for every situation: > > ereg("element[ ]*[=][ ]*[\"]?([^\">]*)[ |\"|>].*" ... > > thanks for your help - regular expressions are not my best area! > > jamie.

« previous php.general (#36698) next »