Regex negative lookahead and word boundary removes first character from capture group -


i trying capture every word in string except 'and'. want capture words surrounded asterisks *this*. regex command using works, when captures word asterisks, leave out first 1 (so *this* have this* captured). here regex i'm using:

/((?!and\b)\b[\w*]+)/gi 

when remove last word boundary, capture of *this* won't leave out of 'and' s.

the problem * not treated word character, \b don't match position before it. think can replace with:

^(?!and\b)([\w*]+)|((?!and\b)(?<=\w)[\w*]+) 

the \b repleced \w (non-word character) match *, first word in string not match because not precedeed non-word character. why added alternative.

demo


Comments