optimize some RegExp code