• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex required for a logic  RSS feed

 
Gunjan Rathii
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write a check which goes like this:
inputs: userName, password
output: boolean true/false

password should not contain 3 consecutive characters in an userName.
For example, if username = "abcd1" then password should not contain consecutive string in it like "abc" or "bcd" or "cd1".
So, if password="xyzabc" then it is not acceptable.

This can be done in many ways but I am looking for a regex for the same.
Please suggest a regex which can take care of this.

Thanks in advance.

 
Raymond Tong
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think using String would be cleaner and faster. Any reason to use regex?
 
Gunjan Rathii
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have currently:


Thinking of doing it without using a loop. Hope, regex would be helpful in this regard.
A guidance in "how to" find the regex for the same would be really helpful.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the Javadoc page of java.util.regex.Pattern. But I agree that in this case, the loop doesn't look that bad. A regex has some overhead, so the loop may actually be faster.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!