4 | title: Named capture groups in regular expressions 5 | status: proposal 6 | stage: 3 7 | location: https://github.com/tc39/proposal-regexp-named-groups 8 | copyright: false 9 | contributors: Daniel Ehrenberg 10 |11 | 12 | 13 | 14 |
The abstract operation BackreferenceMatcher takes one argument, an integer _n_, and performs the following steps:
108 |The production
When the abstract operation RegExpInitialize with arguments _obj_, _pattern_, and _flags_ is called, the following steps are taken:
140 |The abstract operation RegExpBuiltinExec with arguments _R_ and _S_ performs the following steps:
166 |When the `replace` method is called with arguments _searchValue_ and _replaceValue_, the following steps are taken:
231 |The `replace` function is intentionally generic; it does not require that its *this* value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.
255 |The abstract operation GetSubstitution performs the following steps:
260 |281 | Code units 282 | | 283 |284 | Unicode Characters 285 | | 286 |287 | Replacement text 288 | | 289 |
---|---|---|
292 | 0x0024, 0x0024 293 | | 294 |295 | `$$` 296 | | 297 |298 | `$` 299 | | 300 |
303 | 0x0024, 0x0026 304 | | 305 |306 | `$&` 307 | | 308 |309 | _matched_ 310 | | 311 |
314 | 0x0024, 0x0060 315 | | 316 |
317 | $`
318 | |
319 | 320 | If _position_ is 0, the replacement is the empty String. Otherwise the replacement is the substring of _str_ that starts at index 0 and whose last code unit is at index _position_ - 1. 321 | | 322 |
325 | 0x0024, 0x0027 326 | | 327 |328 | `$'` 329 | | 330 |331 | If _tailPos_ ≥ _stringLength_, the replacement is the empty String. Otherwise the replacement is the substring of _str_ that starts at index _tailPos_ and continues to the end of _str_. 332 | | 333 |
336 | 0x0024, N
337 | 338 | Where 339 | 340 | 0x0031 ≤ N ≤ 0x0039 341 | |
342 |
343 | `$n` where
344 | 345 | `n` is one of `1 2 3 4 5 6 7 8 9` and `$n` is not followed by a decimal digit 346 | |
347 | 348 | The _n_th element of _captures_, where _n_ is a single digit in the range 1 to 9. If _n_≤_m_ and the _n_th element of _captures_ is *undefined*, use the empty String instead. If _n_>_m_, the result is implementation-defined. 349 | | 350 |
353 | 0x0024, N, N
354 | 355 | Where 356 | 357 | 0x0030 ≤ N ≤ 0x0039 358 | |
359 |
360 | `$nn` where
361 | 362 | `n` is one of `0 1 2 3 4 5 6 7 8 9` 363 | |
364 | 365 | The _nn_th element of _captures_, where _nn_ is a two-digit decimal number in the range 01 to 99. If _nn_≤_m_ and the _nn_th element of _captures_ is *undefined*, use the empty String instead. If _nn_ is 00 or _nn_>_m_, no replacement is done. 366 | | 367 |
370 | 0x0024, 0x003C 371 | | 372 |373 | `$<` 374 | | 375 |
376 | |
388 |
391 | 0x0024 392 | | 393 |394 | `$` in any context that does not match any of the above. 395 | | 396 |397 | `$` 398 | | 399 |
When the @@`replace` method is called with arguments _string_ and _replaceValue_, the following steps are taken:
409 |The value of the `name` property of this function is `"[Symbol.replace]"`.
471 |The syntax of
This alternative pattern grammar and semantics only changes the syntax and semantics of BMP patterns. The following grammar extensions include productions parameterized with the [U] parameter. However, none of these extensions change the syntax of Unicode patterns recognized when parsing with the [U] parameter present on the goal symbol.
477 |When the same left hand sides occurs with both [+U] and [\~U] guards it is to control the disambiguation priority.
563 |