Fixed search bug due to regex lastIndex attribute when using g type