wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes RegularExpression in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "RegularExpression in Java" Watch "RegularExpression in Java" New topic
Author

RegularExpression in Java

James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
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

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

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.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
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

Joined: Sep 07, 2004
Posts: 781

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

Joined: Sep 15, 2010
Posts: 115
yes James, I changed and it is working.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RegularExpression in Java