Php preg_match – test online

Input
Pattern example: /abc/i
Content

preg_match usage

PHP regular expression match

$retval = preg_match($pattern, $content [, array &$matches [, int $flags = 0 [, int $offset = 0]]])
(this page is using $flags=PREG_OFFSET_CAPTURE)

Notes on preg_match behavior

  1. $matches[0] is full pattern match and $matches[1] is subpatten match for first parentheses subpattern and so on.
  2. The regex pattern must be delimited by a valid delimiter. e.g. /abc/, #abc#, etc.
  3. The modifier flag “i” after / is specified to ignore case while matching. You can combine multiple flags. For a full list if flags you can visit PHP: possible modifiers in regex patterns – manual.
  4. Php preg_match follows PCRE – Perl compatible regular expressionss.
  5. Official document for preg_match can be viewed at PHP: preg_match manual.
  6. Also visit: Regular expression – Wikipedia.