|
Posted by Sandman on 11/03/05 20:06
In article <1131039971.857434.161370@g49g2000cwa.googlegroups.com>,
"Paul" <paul.maunders@gmail.com> wrote:
> Hi,
>
> Does anyone know if it's possible to use regular expressions to grab
> all content between two words. For example....
>
> ------
> This is some example text to illustrate my problem and here's another
> my for you.
> ------
>
> I want to grab all text between the words 'some' and 'my' with the
> correct result being ' example text to illustrate '
>
> The following doesn't work with either ereg or preg_match...
>
> some([^(my)]+)my
>
> Anyone got any ideas? Is this even possible with regular expressions?
Of course. :)
#!/usr/bin/php
<?
$string = "This is some example text to illustrate my problem and here's
another my for you.";
if (preg_match("/some(.*?)my/", $string, $m)){
print $m[1];
}
?>
--
Sandman[.net]
Navigation:
[Reply to this message]
|