]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/helpers/regexp.ts
Fix pending subscription deletion
[github/Chocobozzz/PeerTube.git] / server / helpers / regexp.ts
... / ...
CommitLineData
1// Thanks to https://regex101.com
2function regexpCapture (str: string, regex: RegExp, maxIterations = 100) {
3 const result: RegExpExecArray[] = []
4 let m: RegExpExecArray
5 let i = 0
6
7 while ((m = regex.exec(str)) !== null && i < maxIterations) {
8 // This is necessary to avoid infinite loops with zero-width matches
9 if (m.index === regex.lastIndex) {
10 regex.lastIndex++
11 }
12
13 result.push(m)
14 i++
15 }
16
17 return result
18}
19
20export {
21 regexpCapture
22}