Reputation: 173
Hi I'm new to REGEX and want to be able to find a string with any character, white spaces, or a single quote in it. This is what I have:
preg_match('/title="([A-Za-z\'\w]+)"/', 'title="Some ' text"', $match);
echo $match[1];
I want this to output:
Some ' text
Upvotes: 0
Views: 6989
Reputation: 1077
This works, just tested it.
$match = array();
$text = "title=\"Some ' text\"";
preg_match("/[a-z]*\s\'\s[a-z]*/i", $text, $match);
echo print_r($match);
It will out put
Array ( [0] => Some ' text ) 1
Upvotes: 0
Reputation: 652
You should escape quote inside string.
And add \s to your regexp, to match all whitespaces
Also \w covers a-zA-Z
preg_match('/title="([\'\w\s]+)"/', 'title="Some \' text"', $match);
echo $match[1];
Upvotes: 4