The "g" is a flag say says replacements should be made "globally". The default behavior is to only replace the first match.
The use of the "g" flag for this purpose and the syntax of placing it right after a /-delimited regex comes from ed (and also appears in ex, sed, vi, etc.).