Php preg_match_all – test online

Input
Pattern example: /abc/i
Content

preg_match_all usage

PHP regular expression match

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

Notes on preg_match_all behavior

  1. Above flags can be combined with PREG_OFFSET_CAPTURE to capture the offset of the match.
  2. For flag PREG_SET_ORDER $match[0] contains first set of matches (pattern and its subpattern if any), $match[1] contains second and so on.
  3. The regex pattern must be delimited by a valid delimiter. e.g. /abc/, #abc#, etc.
  4. 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.
  5. Php preg_match_all follows PCRE – Perl compatible regular expressionss.
  6. Official document for preg_match_all can be viewed at PHP: preg_match_all manual.
  7. Also visit: Regular expression – Wikipedia.