keepup-ECMAScript
CtrlK
  • About
  • Proposal
    • using
    • Temporal
  • ES2025
    • Promise.try
    • Sync Iterator helpers
    • Import Attributes
    • JSON Modules
    • New Set Methods
    • RegExp Modifiers
    • Duplicate named capture groups
  • ES2024
    • Resizable and growable ArrayBuffers
    • RegExp v flag with set notation + properties of strings
    • Atomics.waitAsync
    • Well-Formed Unicode Strings
    • array grouping
    • Promise withResolvers
  • ES2023
    • Symbols as WeakMap key
    • Hashbang Grammar
    • Array.findLast, findLastIndex
    • 配列の非破壊操作
  • ES2022
    • Private class fields
    • Regexp match indices
    • Top-level await
    • Private fields in-in
    • Array.at
    • Object.hasOwn
    • Class static block
    • Error cause
GitBook提供
このページ内
  • Example
  • Link
GitHubで編集
  1. ES2022

Regexp match indices

d フラグを付けて正規表現で検索した場合に、マッチした位置を indices から得られるようになった。

Example

const text = "abc-abc*abc/abc";
const regex = /(?<text>abc)/dg;

for (match of text.matchAll(regex)) {
  console.log(match);
  // { indices: { groups: { text: [0,4] } } }
  // { indices: { groups: { text: [4,7] } } }
  // { indices: { groups: { text: [8,11] } } }
  // { indices: { groups: { text: [12,15] } } }
}

Link

LogoGitHub - tc39/proposal-regexp-match-indices: ECMAScript RegExp Match IndicesGitHub
LogoJavaScript built-in: RegExp: hasIndices | Can I use... Support tables for HTML5, CSS3, etc
Logo正規表現 - JavaScript | MDN
前へPrivate class fields次へTop-level await

最終更新 2 年前