Skip to content

Instantly share code, notes, and snippets.

@nakasyou
Created March 12, 2023 01:37
Show Gist options
  • Save nakasyou/c89a9c2e82980ab71a2fbfe4b2dfa03e to your computer and use it in GitHub Desktop.
Save nakasyou/c89a9c2e82980ab71a2fbfe4b2dfa03e to your computer and use it in GitHub Desktop.
正規表現からマッチした文字列のindexを抜き出すコード
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