-2

I have the next regular expression:

(?=.*\d)(?=.*[A-Z]).*$

1) Contains one digit.

2) Contains UPPER case letters.

Example:

"asaZ1h" -> Correct 
"asaZaksa" -> Incorrect

My question is what's the meaning of "?=" in this expression ?

Alan Moore
  • 73,866
  • 12
  • 100
  • 156

2 Answers2

1

The meaning of "?=" signifies a lookahead. This means that it'll assert that in a particular string a condition is true, but it won't consume any characters, thus the match that follows will start at the cursor position before the lookaheads. Good if you want to start matching one thing conditionally on another expression.

This might help.

Community
  • 1
  • 1
M Blu
  • 11
  • 1
0

If you're working in javascript (and probably other languages) it means that the match you're trying to make in the parentheses is required.

See this answer for a more thorough - and useful - response.

Community
  • 1
  • 1
chris g
  • 1,088
  • 10
  • 18