开发者

regex space or start of input, space or end of input

开发者 https://www.devze.com 2023-01-14 10:45 出处:网络
I\'m trying to match parts of a larger block of content and want to only match things at t开发者_StackOverflowhe start of the string or that are preceded by a space and I only want to match things tha

I'm trying to match parts of a larger block of content and want to only match things at t开发者_StackOverflowhe start of the string or that are preceded by a space and I only want to match things that end at the end of string or are followed by a space. Unfortunately, my regex-fu is a bit too weak to figure this out on my own. Help me Stack Overflow, you are my only hope.

Basically these should all match "the-thing-to-match";

the-thing-to-match blah
blah the-thing-to-match
blah the-thing-to-match blah


/(?:^| )the-thing-to-match(?: |$)/

EDIT: Remove quantifiers.

0

精彩评论

暂无评论...
验证码 换一张
取 消