i have working regex code, it's not including non-letter characters. how include those?
$text = "i have 1 treehouse. i'm one. have 2 cats."; preg_match_all('/[\w\s]+?\bone\s?[\w\s]*?\./', $text, $array); print_r($array);
expected results
$array[0] = "i have 1 treehouse."; $array[1] = "i'm one";
actual results
$array[0] = "i have 1 treehouse."; $array[1] = "m one"; <---cuts off @ single quote
i think it's because regex code doesn't non-letter characters ',!? , on. how include those?
you need include '
inside character class.
\b[\w'\s]+?\bone\s?[\w\s]*?\.
preg_match_all("~\b[\w'\s]+?\bone\s?[\w\s]*?\.~", $str, $matches);
Comments
Post a Comment