|
Posted by Steve on 11/02/05 20:04
> If I have an url like this:
> http://www.danforthdiamond.com/lawrenceTests/regex/dog/4/
> Why would this regex patter not find something?
> ^(.*)lawrenceTests/regex(.*)$
That depends. What regexp function are you using? If ereg(), no
problem, it will work. If preg_match(), you need delimiters around the
pattern and if you use the standard '/' delimiter you must escape any
'/' in your pattern.
$str = "http://www.danforthdiamond.com/lawrenceTests/regex/dog/4/";
print ereg( "^(.*)lawrenceTests/regex(.*)$", $str ) . "\n";
Prints: 1 (true)
print preg_match( "/^(.*)lawrenceTests/regex(.*)$/", $str ) . "\n";
PHP Warning: Unknown modifier 'r' in ...
print preg_match( "/^(.*)lawrenceTests\/regex(.*)$/", $str ) . "\n";
Prints: 1 (true)
---
Steve
Navigation:
[Reply to this message]
|