]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/regexp.ts
Correctly cleanup sql command
[github/Chocobozzz/PeerTube.git] / server / helpers / regexp.ts
CommitLineData
f7cc67b4
C
1// Thanks to https://regex101.com
2function regexpCapture (str: string, regex: RegExp, maxIterations = 100) {
a1587156 3 const result: RegExpExecArray[] = []
f7cc67b4
C
4 let m: RegExpExecArray
5 let i = 0
f7cc67b4 6
f7cc67b4
C
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}