Refactor regex utils

This commit is contained in:
Unarray 2023-08-23 15:37:28 +02:00
parent 0807664519
commit 3a62bfb151
3 changed files with 10 additions and 3 deletions

View file

@ -1 +1,2 @@
export * from "./regex";
export * from "./regex";
export * from "./regex.util";

View file

@ -1,3 +1,6 @@
export const escapeString = (string: string): string => {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
import { escapeString } from "./regex.util";
export const beginningString = (string: string): RegExp => {
return new RegExp(`^${escapeString(string)}`);
};

View file

@ -0,0 +1,3 @@
export const escapeString = (string: string): string => {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
};