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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -