PHP regular expressions: No ending delimiter '^' found in

PhpRegexPreg MatchPcre

Php Problem Overview

I've been having some trouble with regular expressions.

This is my code

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

if (preg_match($pattern, $input))
   echo "yes";
   echo "nope";

I run it and get:

> Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in

Php Solutions

Solution 1 - Php

PHP regex strings need delimiters. Try:


Also, note that you have a lower case o, not a zero. In addition, if you're just validating, you don't need the capturing group, and can simplify the regex to /^\d+$/.

Example: <>

See also: PHP - Delimiters

Solution 2 - Php

Your regex pattern needs to be in delimiters:


Solution 3 - Php

You can use T-Regx library, that doesn't need delimiters



All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfingermanView Question on Stackoverflow
Solution 1 - PhpKobiView Answer on Stackoverflow
Solution 2 - PhpDavid PowersView Answer on Stackoverflow
Solution 3 - PhpDanonView Answer on Stackoverflow