DWQA QuestionsCategory: ProgramThe X (?= y) and X (?!y) of JavaScript regular expressions
Petal Dairy Cow asked 4 weeks ago

Actually, I understand.x(?=y)andx(?!y)Usage, but I really don’t understand how these two regular expressions work.
Password matching upper and lower case letters and numbers
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$
Password matching 8 bits minimum length of special characters and numbers in upper and lower case letters
(?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
The original website is here at http://html5pattern.com/Passwords.
It’s like this. There are two reasons why you can’t understand it.
1. In Modex(?=y)andx(?!=y)Why is it missing?xCan it match?
2. Continuous several(?=y)How do you understand writing together?

2 Answers
Best Answer
Honwhy answered 4 weeks ago

x(?=y)andx(?!=y)Without x, you can’t match, if you understand (I don’t know how you understand it), but why do you doubt it? Test it.

var re = /x(?=y)/;
console.log(re.test('yy'));
console.log(re.test('xy'));

(?=.*\d)(?=.*[a-z])(?=.*[A-Z])It can be seen as three sets of forward loops. The three groups together (the order is not important) are in the right position of the match, if so.x(?=y)In this form, we say that if x matches, the regular expression continues to match to the right (if the engine transmits the matched characters in this way, regardless of DFA and NFA), but(?=y)Just check to see if there’s y on the right, if there’s another set.(?=z)It’s actually looking at the right side of X.

Dont replied 4 weeks ago

The answer is slow. I think the answer from the 1st floor will be more effective if it is added to you.

Be absent-minded answered 4 weeks ago
  1. (?= y) matches a position (i.e., the position with y behind it), which has nothing to do with whether x exists or not.
  2. Multiple zero-width assertions put together indicate that this location must satisfy multiple conditions at the same time.

The first regular expression means that it must contain a number, a lowercase letter, a capital letter and not a blank character.
Second Identity