Re: preg_match() occurence position
| From: | Tim Fountain | Date: | Thu, 25 Jul 2002 12:43:57 +0000 |
| Subject: | Re: preg_match() occurence position | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-109486@lists.php.net to get a copy of this message | ||
On Thursday, July 25, 2002, Michael Sims wrote:
> On Thu, 25 Jul 2002 15:05:36 +0200, you wrote:
>> for example:
>> $mem='this is a test';
>> preg_match('/test/', ...) should return me somehow: 10
> How about this:
> $mem='this is a test';
> if(preg_match("/(.*)test/",$mem,$matches)) {
> echo strlen($matches[1]);
> }
> Of course, if "test" occurs more than once then the above won't
> work, since regex's are "greedy"...
If you add a ? after the * then that'll make it non-greedy won't it?
--
Tim Fountain (tim@tfountain.co.uk)
http://www.tfountain.co.uk/