Skip to content

Instantly share code, notes, and snippets.

@thagxt
Created April 2, 2016 22:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thagxt/98f5a52cbd0401f0f3fe865e81719a69 to your computer and use it in GitHub Desktop.
Save thagxt/98f5a52cbd0401f0f3fe865e81719a69 to your computer and use it in GitHub Desktop.

Regular expressions syntax

Regular Expression Matches
foo The string “foo”
^foo “foo” at the start of a string
foo$ “foo” at the end of a string
^foo$ “foo” when it is alone on a string
[abc] a, b, or c
[a-z] Any lowercase letter
[^A-Z] Any character that is not a uppercase letter
(gif jpg)
[a-z]+ One or more lowercase letters
[0-9.-] A�ny number, dot, or minus sign
^[a-zA-Z0-9_]{1,}$ Any word of at least one letter, number or _
([wx])([yz]) wy, wz, xy, or xz
[^A-Za-z0-9] Any symbol (not a number or a letter)
([A-Z]{3} [0-9]{4})

PHP regular expression functions

Function Description
preg_match() The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.
preg_match_all() The preg_match_all() function matches all occurrences of pattern in string.
preg_replace() The preg_replace() function operates just like ereg_replace(), except that regular expressions can be used in the pattern and replacement input parameters.
preg_split() The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
preg_grep() The preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
preg_ quote() Quote regular expression characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment