Created
March 12, 2023 01:37
-
-
Save nakasyou/c89a9c2e82980ab71a2fbfe4b2dfa03e to your computer and use it in GitHub Desktop.
正規表現からマッチした文字列のindexを抜き出すコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const regIndexes=(regexp:RegExp,text:string):Array<{start,end}>=>{ | |
let array; | |
const result:Array<{start,end}>=[]; | |
while((array=regexp.exec(text))!==null){ | |
result.push({ | |
start:array.index, | |
end:regexp.lastIndex, | |
}); | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment