php - Regex: How to consider double quotes -
i have following regex in php:
'/\|*([\w\s]*' . $searchterm . '[\w\s]*)\|*/iu' let's assume following searchterm:
stories
how achieve regex match string has double quotes, such as:
stories "neverland"
my current regex matches until double quotes start. how can cover whole string regex, taking double quotes account?
use
'/\|*([\w\s\'"]*' . preg_quote($searchterm, "/") . '[\w\s\'"]*)\|*/iu' just add double quote , escaped single quote (since using single quoted literal declare regex) character classes [...], , not forget escape $searchterm contents preg_quote may contain characters ? or + have special meaning in regex pattern. second argument in preg_quote escape / symbol used regex delimiter in code.
Comments
Post a Comment