Shamoon
Shamoon

Reputation: 43501

How do I match with Regex with word boundaries?

I am using JavaScript:

::add ::stuff more::word

I want to match ::add and ::stuff, but not ::word.

How can I do this?

Upvotes: 0

Views: 53

Answers (1)

hwnd
hwnd

Reputation: 70732

You can use a non-word boundary \B here:

var r = '::add ::stuff more::word'.match(/\B::\w+/g);
console.log(r); //=> [ '::add', '::stuff' ]

Upvotes: 6

Related Questions