Hacker News new | past | comments | ask | show | jobs | submit login

> This update brings the ECMAScript RegExp Match Indices, which provide the start and end indices of the captured string. The

I'm curious, because I'm useless at RegEx.. But will this break current RexEx implementations ??




Apparently it's an additional property "indices" on the returned array.

> ..We propose the adoption of an additional indices property on the array result (the substrings array) of the RegExpBuiltInExec abstract operation (and thus the result from RegExp.prototype.exec(), String.prototype.match, etc.).

> This property would itself be an indices array containing a pair of start and end indices for each captured substring. Any unmatched capture groups would be undefined, similar to their corresponding element in the substrings array. In addition, the indices array would itself have a groups property containing the start and end indices for each named capture group.

> NOTE: For performance reasons, indices will only be added to the result if the d flag is specified.

https://github.com/tc39/proposal-regexp-match-indices

From given example:

  const re1 = /a+(?<Z>z)?/d;

  const s1 = "xaaaz";
  const m1 = re1.exec(s1);

  // indices are relative to start of the input string:
  m1.indices[0][0] === 1;
  m1.indices[0][1] === 5;

  s1.slice(...m1.indices[0]) === "aaaz";




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: