preg_match too greedy

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

 



I'm trying to figure out how to test if a string matches *exactly* another string, using a regexp pattern. The manual says that ereg() is deprecated (in favour of what?) and preg_match() is giving me trouble. The problem is that I'm passing the end-of-line delimiter ($) but it seems to be ignored. An example:

-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';

echo "${url} :: ${test}\n";

echo (preg_match($pattern, $test) != false)
	? 'match'
	: 'no match';
-- snip --

I expected 'no match' but get 'match'.

The reason for the (/)? is to allow for a trailing slash. I've added a '$' to specify that I want to test for the exact string. However, preg_match() tests for the existence of a string and appears to ignore the '$'.

How do I do this?

--
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