![words from these letters words from these letters](https://i.pinimg.com/736x/25/64/ae/2564ae989e607469290252edfa119b03.jpg)
Preg_match_all($expr, $string, $matches) And we can make are expression case-insensitive using the i modifier as well as u modifier to support utf-8 characters.īut how do we actually use this in PHP? Well we want to match all occurrences of the regular expression within the string so we use (you guessed it) preg_match_all(): $string = "Progress in Veterinary Science" We can do that with "any word character" \w escape sequence. But what if the string contains blocks of multiple spaces? What if it contains a space followed by a punctuation character? We probably don't want to match any of those, in fat we probably just want to match letters. So we want to match anything preceded by a space or the first character in the string, so we add a start-of-subject assertion: /(?<=\s|^)./ And because it's the first character in the string, it can't be preceded by a space. But - the first character in the string is a character in the string is one you want extract. This will find any character preceded by a space. So we start with a lookbehind for that space character, followed by any character: /(?<=\s)./
![words from these letters words from these letters](https://www.al-mscoastallaw.com/wp-content/uploads/2021/03/words-containing-letters-bleach.jpg)
The best way to identify those characters is to look for those characters that are preceded by white space. Lets break down what you want in a logical way: You want every character from the string is at the beginning of a word. The best way to accomplish this is with regular expressions.