Reputation: 8297
how to match non-word+word boundary in javascript regex.
"This is, a beautiful island".match(/\bis,\b/)
In the above case why does not the regex engine match till is, and assume the space to be a word boundary without moving further.
Upvotes: 1
Views: 134
Reputation: 48761
\b
asserts a position where a word character \w
meets a non-word character \W
or vice versa. Comma is a non-word character and space is as well. So \b
never matches a position between a comma and a space.
Also you forgot to put ending delimiter in your regex.
Upvotes: 2
Reputation: 786349
You can use \B
after comma that matches where \b
doesn't since comma is not considered a word character.
console.log( "This is, a beautiful island".match(/\bis,\B/) )
//=> ["is,"]
Upvotes: 1