javascript - regex space or start of input, space or end of input - Stack Overflow

I'm trying to match parts of a larger block of content and want to only match things at the start

I'm trying to match parts of a larger block of content and want to only match things at the 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

I'm trying to match parts of a larger block of content and want to only match things at the 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
Share Improve this question asked Aug 28, 2010 at 1:35 Stephen BelangerStephen Belanger 6,36112 gold badges47 silver badges49 bronze badges 1
  • Check out regular-expressions.info/wordboundaries.html too; it may (or may not) be useful. – polygenelubricants Commented Aug 28, 2010 at 12:35
Add a ment  | 

1 Answer 1

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

EDIT: Remove quantifiers.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744611218a4583779.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信