DEV Community

Discussion on: A regex cheatsheet for all those regex haters (and lovers) 👀

Collapse
 
simov profile image
simo

Hey @catherinecodes , I think you've missed the greedy vs lazy matching:

// greedy
/".+"/.exec('a "witch" and her "broom" is one') // "witch" and her "broom"
// lazy
/".+?"/.exec('a "witch" and her "broom" is one') // "witch"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
catherinecodes profile image
catherine

Nice! I didn't learn those yet

Collapse
 
simov profile image
simo

You can achieve laziness with negated set too:

/"[^"]+"/.exec('a "witch" and her "broom" is one') // "witch"
Enter fullscreen mode Exit fullscreen mode