Viewed   68 times

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 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+$/.


See also: PHP - Delimiters

Tuesday, September 6, 2022

var_dump( preg_match( $regex, 'M1 1AA' ), preg_match( $regex, 'not valid' ) );

Works like a charm for me. You need to have delimiters in place.

Monday, November 21, 2022

If a simple pattern would be sufficient depends on how your input could look like.

$re = '~Q$data['infos'][]E.*?);~s';
  • Q...E is used to match literally (also could escape the brackets/dollar).
  • .*? in single line mode (s flag) matches lazily any amount of any character.

See demo at regex101 or php demo at

Sunday, October 30, 2022

When you set the validation rules you separate them with a | so the |'s in your regex is causing the validation rule to split at those and that is causing the error. Discussion here on the issue. It seems it's a limitation or bug in codeigniter. You can test it out by running a regex with and without |'s and see if the usage of pipes will cause an error. If that is the case then you may have to validate by regex by other means, maybe use a callback function as detailed on this page where your function will do a preg_match using the regex which needs to be inside the function of course and then return true/false.

Saturday, December 3, 2022

Did you try the (*CRLF) and related modifiers? They are detailed on Wikipedia here (under Newline/linebreak options) and seem to do the right thing in my testing. i.e. '/(*CRLF)^two$/m' should match the windows rn newlines. Also (*ANYCRLF) should match both linux and windows but I haven't tested this.

Sunday, October 23, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :