Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Add FAQ entry on differences between v and u #63

Merged
merged 6 commits into from
May 18, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,52 @@ In other words, the new flag would indicate several connected changes related to

For more discussion see [issue 2](https://github.com/tc39/proposal-regexp-set-notation/issues/2).

### How is the `v` flag different from the `u` flag?

The answer to this question can be useful when “upgrading” existing `u` RegExps to use `v`. Here’s an overview of the differences:

1. (This is the obvious part.) Previously invalid patterns making use of the new syntax (see above) now become valid, e.g.

```
[\p{ASCII_Hex_Digit}--[Ff]]
\p{RGI_Emoji}
[_\q{a|bc|def}]
```

1. Some previously valid patterns are now errors, specifically those with a character class including either an unescaped [special character](https://arai-a.github.io/ecma262-compare/snapshot.html?pr=2418#prod-ClassSetSyntaxCharacter) `(` `)` `[` `{` `}` `/` `|` (note: `\` and `]` and `-` are omitted from this list since they require escaping with the `u` flag already) or [a double punctuator](https://arai-a.github.io/ecma262-compare/snapshot.html?pr=2418#prod-ClassSetReservedDoublePunctuator):
mathiasbynens marked this conversation as resolved.
Show resolved Hide resolved

```
[(]
[)]
[[]
[{]
[}]
[/]
[-]
[|]
[&&]
[!!]
[##]
[$$]
[%%]
[**]
[++]
[,,]
[..]
[::]
[;;]
[<<]
[==]
[>>]
[??]
[@@]
[^^]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gibson042 @markusicu @macchiati @pthier Is /[^^]/v actually an error? I noticed the current V8 implementation allows it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it isn't, as the first ^ is consumed by the production CharacterClass :: [ ^ ClassContents ], so the remaining ^ is not a reserved double punctuator. [^^^] is an error in V8.
Note that also []] is not a breaking change, as this is an error also with /u.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess [_^^] or, indeed, [^^^] is a better example. I’ll change this. Thanks!

[]] is currently not listed as a breaking change, so I think there’s no action to be taken for that one. Let me know if I misunderstood.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR: #74

[``]
[~~]
```

1. The `u` flag suffers from confusing case-insensitive matching behavior. The `v` flag has different, improved semantics. See [issue #30](https://github.com/tc39/proposal-regexp-set-notation/issues/30) for details.

### What’s the precedent in other RegExp flavors?

Several other regex engines support some or all of the proposed extensions in some form:
Expand Down