Skip to content
Advertisement

How to find if a word immediately followed by a non-letter character exists in a String

I believe the most efficient solution to this issue is to use Regex but I’m uncertain of the syntax. When looking through a sentence, how do you identify if a word followed by a non-letter character (anything other than a,b,c,d,e…) is present in a string. Example below:

JavaScript

Advertisement

Answer

Use the word boundary regex b, which matches between a letter and a non-letter (or visa versa):

JavaScript

See live demo.

Although numbers are also considered “word characters”, this should work for you.

I’ve used a word boundary are the start too so “I want to beat” does not match.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement