Riamus,

You don't need to separate the individual mode letters with a "|" if they're inside [...] in a regex. Your regex should really be one of the following:

/(i|m|s)/gS
or
/([ims])/gS

[...] is a character class and means "match one of the characters specified within these brackets"