Regular expression space or start of input, space or end of input

I am trying to match parts of a larger block of content and I only want to match things at the beginning of the line or with the preceding space, and I only want to combine objects that end at the end of the line or followed by a space. Unfortunately, my regex-fu is a little weak to figure it out on my own. Help me stack overflow, you are my only hope.

Basically, they should all be subject-to-match;

the-thing-to-match blah
blah the-thing-to-match
blah the-thing-to-match blah
+3
source share
1 answer
/(?:^| )the-thing-to-match(?: |$)/

EDIT: Remove quantifiers.

+3
source

Source: https://habr.com/ru/post/1762022/


All Articles