Reputation: 133
How would I write a regex that matches the first letter of each word (going to be capitalising them via PHP), but not the word "and".
So far I have:
/\b([a-z])/ig
This works for matching the first letter of words, but obviously not including anything yet for not matching where the word is "and".
Upvotes: 2
Views: 545
Reputation: 785286
You can use a negative lookahead for this:
/\b(?!and\b)[a-z]/
Negative lookahead (?!and\b)
before \b[a-z]
will allow matching all words starting with lowercase English alphabet except and
.
Upvotes: 5