Skip to solution
hardFrontend

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

1.2k views
01

Understand 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.

regexpunicodees2024
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals/regex interviews. Difficulty: Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every match/exclusion result below was actually run in Node (ES2024, Chrome 117+/Fi

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

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

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 120 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track