Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RegularExpression in Java

 
James Peter
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • 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]
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
yes James, I changed and it is working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic