Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between the g and m modifiers in Javascript regexes?

In javascript regular expressions, you can put in a 'g' modifier for global, and 'm' for multiple. What's the difference between them, or are they the same thing?

like image 940
Ali Avatar asked Oct 31 '25 20:10

Ali


1 Answers

m does not stand for "multiple", but for "multiline". And it makes ^ and $ match at line beginnings and line endings, respectively (instead of just the beginning and ending of the string).

Well, and g really means "global", so that the regex engine continues to find further matches after the first one.

Further reading about regex modifiers.

like image 198
Martin Ender Avatar answered Nov 02 '25 11:11

Martin Ender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!