This is the input line "!!!??"
FIRST regex works similar in Ruby and JS and do what it need to do split this input for two lines contains "!" and "?" respectively:
Example #1 ruby like js /!+|\?+/g
RUBY s.scan(/!+|\?+/).inspect works like as JS s.match(/!+|\?+/g).
And output is: RUBY [ '!!!', '??' ], JS [\"!!!\", \"??\"]
Example #2 ruby is not js /([?!])\1*/
Here ruby and js have different behavior
RUBY s.scan(/([?!])\1*/) not equal to JS s.match(/([?!])\1*/g).
RUBY returns two arrays [[\"!\"], [\"?\"]].
JS returns two strings as like as in the Example #1 [ '!!!', '??' ].
Why /([?!])\1*/ acts different in Ruby and JS?
matchonly returns a single match.