skip to Main Content

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.

2

Answers


  1. /^[^eil]*[EIL][^eil]*$/g appears to work on regexr.com using the string: EdIt thE ExprEssIon & tExt to sEE matchEs.L
    Changing E, I or L to lowercase will not match any more, as you are expecting.

    Notably, you must be running the operation in a case sensitive manner. Since you are doing case sensitive operations, you need [EIL] in the regex string to find those uppercase letters.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search