2019-01-04 02:56:20 -05:00
|
|
|
// Thanks to https://regex101.com
|
|
|
|
function regexpCapture (str: string, regex: RegExp, maxIterations = 100) {
|
2020-01-31 10:56:52 -05:00
|
|
|
const result: RegExpExecArray[] = []
|
2019-01-04 02:56:20 -05:00
|
|
|
let m: RegExpExecArray
|
|
|
|
let i = 0
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|