js workaround for persistent lastIndex in /g regex