RE: [PHP] Calling Regular Expression experts!
| From: | Richard Heyes | Date: | Mon, 24 Jul 2000 10:25:10 +0000 |
| Subject: | RE: [PHP] Calling Regular Expression experts! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-7845@lists.php.net to get a copy of this message | ||
> >> I got a string like this $urldata = .."- SamsungYEPP1.995:- 2.500:-
> >> DiamondRIO 5002.990:- - SonyMemorysti...3.990:- 4.000:- I "..
> >> What I want to do is to get the "1.995" value into a new
> >> string. The problem
> >> is that the 1.995, could look something like this : 1 995
> >> 1985 2.995 1,935
> >> . How Do I write a regular expresion for that?
> >
> >This seems to work quite nicely:
> >
> >preg_match_all('/([0-9]+[,. ]?[0-9]+)/', $urldata, $matches);
> >
> >for($i=0; $i<count($matches[0]); $i++){
> > echo $matches[0][$i]."<BR>\r\n";
> >}
>
> Oki, But If I want the value behind "SamsungYEPP" what should i Do then?
Ok what about this then:
preg_match('/samsungyepp[ ]*([0-9]+[,. ]?[0-9]+)/i', $urldata, $matches);
echo $matches[1]."<BR>\r\n";
Will only produce the one value though. Is case insensitive, but this can be
changed by removing the i. Replace samsungyepp with (for example) diamondrio
to get that value.
--
Richard Heyes
http://www.heyes-computing.net/scripts/
Plain text email only please!