javascriptregex

Regex to check all occurrences of specific letters be capital


I'm trying to create a regex pattern that follows the rules:

  1. All occurrence of the letters E, I, L must be capital strictly.
  2. All other letters must strictly be lowercase.

I'm working with this rule ^[^eil]*[eil][^eil]*$ but having all capital letters also accepts the string.


Solution

  • You might use a match for only E I L, lowercase chars a-z without e i l plus digits _ and non word characters \W

    ^[EILabcdfghjkm-z0-9_\W]+$
    

    Regex demo