?!,? = In regular expressions

let re=/^(?=.*[A-Za-z])(?!.{16,})([A-Za-z'-]*[\s]?[A-Za-z'-]*)$/

The above regular expressions will feel strange compared to the first encounter with children's shoes. Let me explain here.

I checked some information. This? =,?! Writing is actually a pre-judgment writing, which needs to be wrapped in parentheses.

For example,? =. * [A-Za-z]) This part is to first judge whether this string conforms to the format of *. [[A-Za-z], if it does, continue to go down, otherwise it returns false directly;

And?! Is to first determine whether it does not meet, continue if it does not match, return false;

The advantage of writing in this way is that it does not occupy character space, the logic is more clear, and the overall analysis can be performed.

example:

(? =. * [0-9]) 
there is a number after any string 
(? =. * [Az]) 
there is a lowercase letter after any string 
(? =. * [AZ]) 
there is a capital letter after any string

 

 

Published 21 original articles · won praise 2 · Views 7283

Guess you like

Origin blog.csdn.net/qq_31261131/article/details/81170575