Regular Expression to find term in and surrounding words

Use this regular expression to highlight a term in the middle of a sentence:

(?:\S+\s+){0,4}(money is good)\s*(?:\S+\b\s*){0,4}

Here is a great site to test the above regular expression:


Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top