Escaping
There may be instances where you want to include literal characters in patterns that are usually interpreted as meta-characters. This can be accomplished via a \ metacharacter. <?php // Matches literal [ $matches = (preg_match('/\[/', $string) == 1); // Matches literal 1 $matches = (preg_match('/\\/', $string) == 1); // Matches expression delimiter / $matches = (preg_match('/\//', $string) == 1); // Matches any of the standard escape sequences 1r, 1n, or 1t $matches = (preg_match('/\r|\n|\t/', $string) == 1); ?> Note that it is necessary to double-escape " in the second example because the string ’ ' is interpreted to be a single backslash by PHP whether or not it is used in a regular expression. In other cases, no escaping of ” is needed for the escape sequence to be interpreted properly.
© PCRE Extension — Web Scraping >>> Back to TABLE OF CONTENTS <<< | |
Views: 337 | |
Total comments: 0 | |