RexExr, match singles

Junior Spellweaver
Joined
Nov 15, 2009
Messages
106
Reaction score
1
Hello, i am currently trying to make a RegExr Expression that does the following,

The requirements for password is:
Atleast 2 uppercase letters thats not direcly after eachother
Atleast 2 lowercase letters thats not direcly after eachother
Atleast 2 digits thats not direcly after eachother
Atleast 2 signs thats not direcly after eachother

The thing is, i do not know how to make a expression to make sure that the char before and after is not the same, how do i make an expression like that? Sorry if my question is hard to understand. I am beyond grateful for any help, thanks alot guys
 
The entirety of this definition is not context free, which means a single expression is not going to be able to match it for you. However, each case individually is pretty easy to check:

[A-Z][^A-Z]+[A-Z]...
[a-z][^a-z]+[a-z]...
[0-9][^0-9]+[0-9]...
 
Hello, i am currently trying to make a RegExr Expression that does the following,

The requirements for password is:
Atleast 2 uppercase letters thats not direcly after eachother
Atleast 2 lowercase letters thats not direcly after eachother
Atleast 2 digits thats not direcly after eachother
Atleast 2 signs thats not direcly after eachother

The thing is, i do not know how to make a expression to make sure that the char before and after is not the same, how do i make an expression like that? Sorry if my question is hard to understand. I am beyond grateful for any help, thanks alot guys
What are you meaning by "not direcly after eachother"?
Is this not allowed? abcABC123
So the password must look like for example: aBc9eE0
Or is this not allowed? aaBB11

Both is not easy to check, at least for me :scared:, but I can imagine that you can solve it with assertions and back-references.
A simpler regex to check if the string has at least 1 small letter, 1 big letter and a number, and a total length of at least 10 characters:
^(?=.+?[0-9])(?=.+?[A-Z])(?=.+?[a-z]).{10,}$

I doubt that your requirement "2 ... not direcly after eachother" will make the passwords any safer btw :8: That makes it even weaker, because you will get less possible combinations.
 
Last edited:
Both is not easy to check, at least for me :scared:, but I can imagine that you can solve it with assertions and back-references.
A simpler regex to check if the string has at least 1 small letter, 1 big letter and a number, and a total length of at least 10 characters:
^(?=.+?[0-9])(?=.+?[A-Z])(?=.+?[a-z]).{10,}$

Ah that's right, I forgot that zero-widths could be cascaded. You aren't using references here, you're just using a basic zero-width lookahead, so each of those expressions would just have to require at least 2 aren't next to each other:

^(?=.*[0-9][^0-9]+[0-9])(?=.*[A-Z][^A-Z]+[A-Z])(?=.*[a-z][^a-z]+[a-z]).{10,}$

Clever, though this is really ugly. It'd be more readable in code to just implement a loop that updates some boolean flags. I'm not sure what the FSA created by this expression looks like, and it might actually have to scan the string multiple times.
 
Ah that's right, I forgot that zero-widths could be cascaded. You aren't using references here, you're just using a basic zero-width lookahead, so each of those expressions would just have to require at least 2 aren't next to each other:

^(?=.*[0-9][^0-9]+[0-9])(?=.*[A-Z][^A-Z]+[A-Z])(?=.*[a-z][^a-z]+[a-z]).{10,}$

Clever, though this is really ugly. It'd be more readable in code to just implement a loop that updates some boolean flags. I'm not sure what the FSA created by this expression looks like, and it might actually have to scan the string multiple times.
Well, I didn't say that my regex uses (back-)references, I just said, it maybe could be done using them.
Your regex is also not what xAdrianRonsten needs, for example "Adrian#a1#Anton#2" would not match. To achieve that, the regex needs to check if the previous character (not just character class) is different from the current.
However, you are right, regexes are not very readable - at least for "normal" people.
 
Well, I didn't say that my regex uses (back-)references, I just said, it maybe could be done using them.
Your regex is also not what xAdrianRonsten needs, for example "Adrian#a1#Anton#2" would not match. To achieve that, the regex needs to check if the previous character (not just character class) is different from the current.
However, you are right, regexes are not very readable - at least for "normal" people.

It matches that string just fine o.o. But it can't be done using lookbehinds because no regex engine does backwards recursion, so the lookbehind assertions have to be simple. You'd have to encode every possible password for a lookbehind to work, in which case a hash table would be simpler.
 
Back