From f7cc67b455a12ccae9b0ea16876d166720364357 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Jan 2019 08:56:20 +0100 Subject: Add new follow, mention and user registered notifs --- server/helpers/regexp.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 server/helpers/regexp.ts (limited to 'server/helpers/regexp.ts') diff --git a/server/helpers/regexp.ts b/server/helpers/regexp.ts new file mode 100644 index 000000000..2336654b0 --- /dev/null +++ b/server/helpers/regexp.ts @@ -0,0 +1,23 @@ +// Thanks to https://regex101.com +function regexpCapture (str: string, regex: RegExp, maxIterations = 100) { + let m: RegExpExecArray + let i = 0 + let result: RegExpExecArray[] = [] + + // tslint:disable:no-conditional-assignment + while ((m = regex.exec(str)) !== null && i < maxIterations) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === regex.lastIndex) { + regex.lastIndex++ + } + + result.push(m) + i++ + } + + return result +} + +export { + regexpCapture +} -- cgit v1.2.3