Delimiters in php

Perl-style regular expressions emulate the Perl syntax for patterns, which means that each pattern must be enclosed in a pair of delimiters. Traditionally, the slash (/) character is used; for example, /pattern/. However, any nonalphanumeric character other than the backslash character () can be used to delimit a Perl-style pattern. This is useful when matching strings containing slashes, such as filenames. For example, the following are equivalent:

preg_match(“/\/usr\/local\//”, “/usr/local/bin/perl”); // returns true
preg_match(“#/usr/local/#”, “/usr/local/bin/perl”); // returns true

Parentheses (()), curly braces ({}), square brackets ([]), and angle brackets () can be used as pattern delimiters:

preg_match(“{/usr/local/}”, “/usr/local/bin/perl”); // returns true

Leave a Comment