const reRegExpChar = /[\\^$.*+?()[\]{}|]/g ; const reHasRegExpChar = RegExp ( reRegExpChar . source ) ; since category param { string } str returns { string } function escapeRegExp ( str ? ) { return ( str && reHasRegExpChar . test ( str ) ) ? str . replace ( reRegExpChar , '\\$&' ) : ( str || '' ) ; } export default escapeRegExp ;