PHP regular expressions: trailing delimiter '^' found in

I had problems with regular expressions.

This is my code.

$pattern = "^([0-9]+)$"; if (preg_match($pattern, $input)) echo "yes"; else echo "nope"; 

I run it and get:

Warning: preg_match () [function.preg-match]: Trailing delimiter '^' not found in

+49
php regex preg-match pcre
Jan 08 2018-11-11T00:
source share
2 answers

PHP regular expression strings need separators. Try:

 $numpattern="/^([0-9]+)$/"; 

Also, note that you have a lowercase o, not a zero. Also, if you just check, you don't need a capture group and can simplify the regex to /^\d+$/ .

Example: http://ideone.com/Ec3zh

See also: PHP delimiters

+85
Jan 08 2018-11-11T00:
source share

Your regex pattern should be in delimiters:

 $numpattern="/^([0-9]+)$/"; 
+12
Jan 08 '11 at 17:05
source share



All Articles