Skip to the solution
HardFrontend6 min read

What does the RegExp v flag (Unicode Sets) add over the u flag?

1.2k views

The problem

Question presented to candidate: "If you want a character class that matches any lowercase letter EXCEPT vowels, can you write that with the u flag? What does the v flag actually add that makes this possible?"

What a strong answer should cover:

  • 📌 Interview term: the v flag (unicodeSets mode) — a real, ES2024 superset of the u flag, adding set-notation operations directly inside a character class: subtraction (--) and intersection (&&) — capabilities the u flag genuinely does not support at all.
  • 📌 Interview term: the real, direct answer to the prompt — verified directly: /[[a-z]--[aeiou]]/v — a real, working character-class SUBTRACTION — correctly matched a consonant (b) and correctly EXCLUDED a vowel (a) — this exact expression is genuinely not expressible with the u flag at all, which has no subtraction syntax.
  • 📌 Interview term: character-class intersection — verified directly: /[[a-z]&&[a-m]]/v correctly matched a letter in BOTH ranges (c) and correctly excluded one only in the second range (p) — another real, v-flag-only capability.
  • 📌 Interview term: u and v are mutually exclusive — verified directly: combining both flags on the same regex genuinely throws a real SyntaxError — a precise answer names that v is a genuine REPLACEMENT/superset for u, not an additive flag used alongside it.
  • A precise answer names that the v flag also unlocks matching Unicode "properties of strings" (multi-codepoint sequences like certain emoji) inside a set, a real capability beyond the single-codepoint matching the u flag's property escapes support — the concrete motivating use case for the proposal's real name, "Unicode Sets."

Clarifying questions expected:

  • None — this is a definitional/technical question; directly answering the prompt's own subtraction scenario (genuinely impossible with u, genuinely possible with v) is the strong signal.

Code / implementation expected: Yes — the real, working subtraction and intersection examples are the clearest, most convincing demonstration of a genuinely new capability, not just a synonym for u.

  • regexp
  • unicode
  • es2024

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

6 min read · 8 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal proof: the v flag's character-class subtraction and intersection, both genuinely impossible with the u flag, plus the real mutual-exclusivity error

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 120 of 165 in JavaScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextHard

What are function composition and pipe?

Continue