VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-regexp-u-modifier/

⇱ JavaScript RegExp u Modifier - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript RegExp u Modifier

Last Updated : 23 Jul, 2025

The u modifier in JavaScript regular expressions (RegExp) enables Unicode support, ensuring that the pattern correctly interprets and matches Unicode characters, including those beyond the Basic Multilingual Plane (BMP), such as emojis and special symbols. Without the 'u' modifier, regular expressions may not handle these characters properly, leading to unexpected behaviour.


Output
true
true
  • Without u: The regex fails to recognize the Unicode character "😊" because JavaScript, by default, treats it as two separate code units.
  • With u: The regex correctly interprets the character as a single Unicode character.

Syntax

let regex = /pattern/u;

Key Points

  • Unicode Matching: Ensures proper handling of characters like emojis, accented characters (e.g., é), and symbols.
  • Code Point Escapes: Works with Unicode escape sequences (\u{}) to match characters by their Unicode code points.
  • Surrogate Pairs: Correctly processes surrogate pairs, which represent characters outside the BMP.

Real-World Examples of the u Modifier

1. Matching Emojis


Output
true

2. Accented Characters


Output
true

3. Using Unicode Code Points


Output
true

4. Matching a Unicode Range

5. Case-Insensitive Matching with Unicode


Output
true

6. Matching Words with Special Characters


Output
true
true

7. Handling Complex Unicode Characters

The u modifier allows accurate parsing of combining characters:


Output
false
Comment