Forums Register Login

Regex required for a logic

+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
I think using String would be cleaner and faster. Any reason to use regex?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 753 times.
Similar Threads
Invalid user error message
get JavaBean properties in any jsp not just consecutive
Java regular expression optimization - help needed
Validations at client side
regex question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:10:44.