• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regex required for a logic

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 258
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic