1 of 16

RegExp status update

Stage 3 proposals

2 of 16

RegExp dotAll mode (s flag)

3 of 16

RegExp named capture groups

4 of 16

RegExp lookbehind assertions

  • Test262 tests:
  • Compatible native implementations:
    • Chrome 62 (stable)
    • Seeking more implementations!
  • tc39/ecma262 PR: https://github.com/tc39/ecma262/pull/1029
  • Stage 4 blocked on more implementations

5 of 16

RegExp Unicode property escapes

  • Test262 tests:
  • Compatible native implementations:
    • Chrome 64 (preview)
    • Safari TP 42 (preview)
  • tc39/ecma262 PR: TODO (pending some final spec tweaks)
  • Ready for Stage 4 soon

6 of 16

String.prototype.replaceAll

Stage 0 proposal

7 of 16

  • Currently, no choice but to use a global RegExp
  • Downside: need to escape RegExp meta-characters in substring
    • (and the RegExp.escape proposal was rejected)

Replace all substring instances

8 of 16

  • Currently, no choice but to use a global RegExp
  • Downside: need to escape RegExp meta-characters in substring
    • (and the RegExp.escape proposal was rejected)

Replace all substring instances

9 of 16

const queryString = 'q=query+string+parameters';const withSpaces = queryString.replace(/\+/g, ' ');

10 of 16

const queryString = 'q=query+string+parameters';const withSpaces = queryString.replaceAll('+', ' ');

11 of 16

  • Simplified API for a common use case that does not require RegExp knowledge
  • Global-replace strings without having to escape RegExp syntax characters
  • Possibly improved optimization potential on the VM side

String.prototype.replaceAll

12 of 16

  • Option 1:
    • throw if searchValue is a RegExp
    • otherwise, use ToString(searchValue)
  • Option 2:
    • unconditionally use ToString(searchValue), even if searchValue is a RegExp
    • downside: this breaks RegExp args in unexpected ways
      • e.g. /./.toString() // → '/[.]/'

replaceAll(searchValue, replaceValue)

13 of 16

  • Option 3:
    • if searchValue is a RegExp, create a clone including the g flag and dispatch to RegExp.prototype[@@replace]
    • otherwise, use ToString(searchValue)
    • + follows precedent from RegExp.prototype[@@split]
    • + seems consistent with user expectations
    • - lose efficiency and simplicity on the implementation side
    • - unexpected performance trap (cloning RegExp instances)

replaceAll(searchValue, replaceValue)

14 of 16

  • Option 1:
    • use ToString(replaceValue)
    • don’t perform GetSubstitution
    • throw if replaceValue is callable
    • + keeps things simple (compared to replace)
    • + less cognitive load for users
    • + more efficient implementations for VMs
  • Option 2:
    • same as option 1, but perform GetSubstitution for consistency with replace
    • - adds complexity and overhead to implementation

replaceAll(searchValue, replaceValue)

15 of 16

  • Option 3:
    • same as option 2
    • but additionally allow callable replaceValue for more consistency with replace
    • then we also need to support GetSubstitution semantics for replaceValue for consistency
    • - adds even more complexity and overhead to implementation
    • + less cognitive load for users
    • + more efficient implementations for VMs

replaceAll(searchValue, replaceValue)

16 of 16

Stage 1?