Reputation: 5469
Let's assume I have some text:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
adipiscing elit, sed do eiusmod tempor
dolore magna aliqua
etc
I believe the best way is to do it with Regex (it's not must-have), but I don't know how to construct such a query.
Upvotes: 0
Views: 78
Reputation: 727047
This can be done by surrounding the target word with \s?\S*\s?\S*
, like this:
\S*\s?\S*\s?consectetur\s?\S*\s?\S*
Since space \s
is optional and \S*
can match zero characters, this works on both ends of the text as well (demo 2, demo 3).
Note: This approach does not work too well when words are separated by multiple spaces, because it relies on counting whitespace.
Upvotes: 1