javascript - Why can't '\b\w+(?=ing)\b' match "I'm singing while you're dancing" -


i have following regex

var reg = /\b\w+(?=ing)\b/g; var str = "i'm singing while you're dancing"; str.match(reg) // ==>null 

but if regex /\b\w+(?=ing\b)/g str can match 'sing,danc'

why mach previous example doesn't?

you need remove \b @ end since part want match not end on boundary . danc , sing batch \b\w+\b dancing , singing not

\b\w+(?=ing) 

check demo here

\b\w+(?=ing\b) 

would make sure ing @ boundary , not

\w+ 

part


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -