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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -