0

This blows my mind.

var rexPassword = /[A-Z]/g;

console.log(rexPassword.test('Password1!'));
console.log(rexPassword.test('Password1!'));
console.log(rexPassword.test('Password1!'));

This is the same exact regular expression testing against the same exact string constant, but the output alternates as follows:

true
false
true

What is going on here?!

Fiddle

CRice
  • 29,968
  • 4
  • 57
  • 70
Jordan
  • 9,642
  • 10
  • 71
  • 141
  • 1
    Get rid of the "g" flag. – Pointy Mar 26 '18 at 16:46
  • 2
    You may benefit from [Reference - Password Validation](https://stackoverflow.com/questions/48345922/reference-password-validation/) – ctwheels Mar 26 '18 at 16:46
  • @ctwheels thanks + 1 – Jordan Mar 26 '18 at 16:52
  • 3
    @Jordan ?? Having a question closed as a duplicate is not a *punishment* or anything like that; your question simply **is** a duplicate, one that's asked quite often. If you click through the link, you'll see the answers that have already been provided for exactly the same problem. – Pointy Mar 26 '18 at 17:00
  • @Pointy, yeah, that makes sense. I'm just a little bit jumpy from previous abuse I've received on here. I've been called names. I deleted my comment. I'll delete this one two. Thanks again. – Jordan Mar 30 '18 at 12:45

0 Answers0