Capture Groups "()" Vs Global Flag "g"

I just finished the topic

Reuse Patterns Using Capture Groups
link

And after going back over the Global flag “g” topic again, I can’t see any differences between Capture Groups and the ‘g’ Global flag.

Are there any practical advantages of one over the other that would help me better understand their differences?

they do not do the same

you can’t test if a string has two identical consecuive words doing
/\w+/g (also do not use g flag with test method), but you can with /(\w+)\s\1/

2 Likes