You are here: Re: another dumb regex question « All PHP « IT news, forums, messages
Re: another dumb regex question

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация