Added function to escape regex characters

This commit is contained in:
Paweł Malak
2021-11-12 14:02:19 +01:00
parent 6281994be8
commit b848cfd921
3 changed files with 16 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
/**
* https://stackoverflow.com/a/30851002/16957052
*/
export const escapeRegex = (exp: string) => {
return exp.replace(/[-[\]{}()*+!<=:?.\/\\^$|#\s,]/g, '\\$&');
};

View File

@@ -11,3 +11,4 @@ export * from './validators';
export * from './parseTime';
export * from './decodeToken';
export * from './applyAuth';
export * from './escapeRegex';