TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   preg_match problem (http://www.talkphp.com/advanced-php-programming/2806-preg_match-problem.html)

Village Idiot 05-15-2008 01:21 PM

preg_match problem
 
When I run this expression in preg_match is returns
Quote:

Warning
Quote:

: preg_match() [function.preg-match]: Unknown modifier ']' in /home/img911/public_html/url/shorten.php on line 16
The expression is
Code:

/^(ftp|http|https):\/\/([_a-z\d\-]+(\.[_a-z\d\-]+)+)(([_a-z\d\-\\\.\/]+[_a-z\d\-\\\/])+)*/

Salathe 05-15-2008 02:14 PM

The problem lies in the final character class definition [_a-z\d\-\\\/], the escaping back slashes cause it. They're interpreted (by the PHP parser) to be \\/ which the regex parser decides is a single backslash followed by a forward slash, the pattern delimiter. To match a backslash, you'll need four consecutive backslashes (plus 1 escaping the forward slash!): [_a-z\d\-\\\\\/]

It might also make life easier if you use a different delimiter for the pattern, which would save you having to escape all of those forward slashes: ~test://~ vs /test:\/\//


All times are GMT. The time now is 05:34 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0