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

Add FAQ about not-proper-subset subtraction #36

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Changes from all 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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ Matching the longest strings first is key to the integration with properties of

For more details on the rationale for matching longest strings first, see [issue #25](https://github.com/tc39/proposal-regexp-set-notation/issues/25).

### How does subtraction behave in the case of `A--B` where `B` is not a proper subset of `A`?

As mentioned in the answer to the previous question, according to both the current ECMAScript specification and other regular expression implementations, **character classes are mathematical sets**. As such, the removal of strings that are not present in the original set is not an error, but rather a no-op. Example (note that `RGI_Emoji` includes the string `🇧🇪`, but `RGI_Emoji_ZWJ_Sequence` does not):

```
# Proper subset.
[\p{RGI_Emoji}--(🇧🇪)]
# Not a proper subset.
[\p{RGI_Emoji_ZWJ_Sequence}--(🇧🇪)]
```

It would be confusing and counterproductive if one of these patterns threw an exception.

Several of [the real-world illustrative examples in this explainer](https://github.com/tc39/proposal-regexp-set-notation#illustrative-examples) rely on this useful `A--B` pattern, and it is crucial that we support it. [See issue #32 for more background.](https://github.com/tc39/proposal-regexp-set-notation/issues/32)

### What about symmetric difference?

We considered also proposing an operator for symmetric difference (see [issue #5](https://github.com/tc39/proposal-regexp-set-notation/issues/5)), but we did not find a good use case and wanted to keep the proposal simple.
Expand Down