Re: preg_match too greedy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Lucas wrote:
>> I expected 'no match' but get 'match'.
[8<]
> cut/paste your code and it works for me.

Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?

If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:

>> $url = '/foo(/)?';

I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.

>> echo (preg_match($pattern, $test) != false)

The " != false " here is redundant. Combined with the ternary operator, the
logical switchbacks make me a little dizzy (especially this close to lunchtime).

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux