• 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

RegularExpression in Java

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Below is my code.



if i make individual patterns then output is coming properly.

but i want to get same output with one of below pattern.



but both are not working with min max length condition of the string. please let me know where i am doing wrong.

Thanks
Peter


[HENRY: Added Code Tags]
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code. It will highlight your code and make it much easier to read. It probably will also increase the number of people helping you. Also use proper indentation. This is hard to read. You can edit your post with the button.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Peter wrote:
but both are not working with min max length condition of the string. please let me know where i am doing wrong.



How are you using the expression? Are you using the find() method? Or the matches() method?

With the second password pattern, the matches() method should work (or at least, by eyeballing it, I didn't actually try it out).

Henry
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) You haven't included '&' in your set of 'special' characters!
2) You need to use matches() and not find() or the length check term will pass for lengths greater than 7.

P.S. What business case can be made for limiting a password to less than 8 characters? Seems daft to me as presumably one is only storing a seeded digest and not the full password and it reduces significantly the entropy of the allowable passwords.
 
James Peter
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Henry,

Thanks for adding code tag. I was about to do that.

Hi James,

thanks for your comment. I forgot to add "&" character in the set. after adding it is working fine.


Rgds
Peter
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Peter wrote:Hi Henry,

Thanks for adding code tag. I was about to do that.

Hi James,

thanks for your comment. I forgot to add "&" character in the set. after adding it is working fine.


Rgds
Peter



But did you fix the 'length' term and change to use matches() rather than find()?
 
James Peter
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes James, I changed and it is working.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic