Skip to main content

js/noSingleCharRegexAlternatives

disallow the use of single character alternations in regular expressions

Examples

Invalid

/a|b/

 filename.ts:1:1 lint/js/noSingleCharRegexAlternatives  FIXABLE  ━━━━━━━━━━

  No single character alternations in regular expressions. Use a
    character class instead.

    /a|b/
     ^^^

  Safe fix

  - a|b
  + [ab]


/a|b|c/

 filename.ts:1:1 lint/js/noSingleCharRegexAlternatives  FIXABLE  ━━━━━━━━━━

  No single character alternations in regular expressions. Use a
    character class instead.

    /a|b|c/
     ^^^^^

  Safe fix

  - a|b|c
  + [abc]

Valid

/[ab]/
/ab|ba/
/a/
/ab|ba|a/