preg_match find multiple partial appearances of a word in a string
- by Rubytastic
Any regex gurus around here? its driving me crazy.
Say I have this string:
"bookstore books Booking"
I want to count the number "books" appears in this and return the number.
Currently I have this which is not working:
$string = "bookstore books Booking";
if (preg_match_all('/\b[A-Z]+books\b/', $string, $matches)) {
echo count($matches[0]) . " matches found";
} else {
echo "match NOT found";
}
On top of this the "books" inside the preg_match_all should become a $var
Anyone an idea how to count correctly?