Skip to content

regexp/no-misleading-unicode-character

💼 This rule is enabled in the ✅ plugin:regexp/recommended config.

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

disallow multi-code-point characters in character classes and quantifiers

📖 Rule Details

This rule reports misleading Unicode characters.

Some Unicode characters like '❇️', '🏴‍☠️', and '👨‍👩‍👦' consist of multiple code points. This causes problems in character classes and around quantifiers. E.g.

js
> /^[❇️🏴‍☠️]$/.test("🏴‍☠️")
false
> /^👨‍👩‍👦{2,4}$/.test("👨‍👩‍👦👨‍👩‍👦")
false
> /^[❇️🏴‍☠️]$/.test("🏴‍☠️")
false
> /^👨‍👩‍👦{2,4}$/.test("👨‍👩‍👦👨‍👩‍👦")
false

This rule is inspired by the no-misleading-character-class rule.

Now loading...

🔧 Options

json
{
  "regexp/no-unused-capturing-group": ["error", {
    "fixable": true
  }]
}
{
  "regexp/no-unused-capturing-group": ["error", {
    "fixable": true
  }]
}
  • fixable: true | false

    This option controls whether the rule is fixable. Defaults to false.

    This rule is not fixable by default. Misleading Unicode characters can typically be fixed automatically by assuming that users want to treat one displayed character as one regex character. However, this assumption is not useful in all languages, so this rule provides suggestions instead of fixes by default.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-regexp v1.2.0

🔍 Implementation