Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

Help with a RegEx?

 
andi miami
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi! I am almost done with the project y'all have been helping me on, (thanks!), but I can't seem to some up with a RegEx that works for this scenario. Can someone help me?

It must have at least one special character out of these:

!@#$%^

and it has to be made of either letters (any case), numbers, and the special characters !@#$%^&*()_-+<>?:

So, I think it should use the look ahead ?= !@#$%\\^ and then do I need the + sign for one or more instances?

and then any word character including newline is \\w* (0 or more instances)

and any digit is \\d* (0 or more instances)

and then just add in the special characters I am missing, but how do I string this all together? I've tried many ways and I keep getting either a syntax error or

it just doesn't match test passwords that meet these requirements.

Thanks for helping...again! Hahaha.
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can you rephrase your problem? is it the password validation you are trying to do? what are the requirements(min and max number of characters, mandatory characters etc)
 
andi miami
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
It is sort of like a password validation, but it is just a regex matcher type thing. No need to worry about min or max chars. The requirements are simply that which I have listed:

It MUST have at least one special character out of these:

!@#$%^

and it can only be made of either letters (any case), numbers, and any of the the special characters !@#$%^&*()_-+<>?:

So, the letters, numbers and symbols above can be 0 or more instances.

If the test password was only !@#$%^ it would be valid, technically. Make sense? I might be phrasing it badly. I just can't seem to get it grouped correctly. Thanks for taking a look...

 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Report post to moderator
Check this temporary solution while one of us will get back to you with regex soon.
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Report post to moderator
Try this code...hope it helps

 
fred rosenberger
lowercase baba
Bartender
Posts: 12124
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is there a requirement that is has to be done with a regex? and that it has to be done with a SINGLE regex?

Sometimes it's easier to make multiple passes over the candidate string, each time validating part of the requirements..
 
Campbell Ritchie
Sheriff
Pie
Posts: 48957
60
  • Mark post as helpful
  • send pies
  • Report post to moderator
fred rosenberger wrote:Is there a requirement that is has to be done with a regex? and that it has to be done with a SINGLE regex?

Sometimes it's easier to make multiple passes over the candidate string, each time validating part of the requirements..
That may mean that your expression does not arise from a regular grammar. You can only use regular expressions to parse something arising from a regular grammar.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Report post to moderator
Harsha Smith wrote:Try this code...hope it helps


That won't work for the second part of the requirement. Neither will your temporary solution.
it can only be made of either letters (any case), numbers, and any of the the special characters !@#$%^&*()_-+<>?:

Try
String password = "#.,";
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Report post to moderator
@Joanne Neal
would you mind retrying? I'll wait for the thread starter's response
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Report post to moderator
Harsha Smith wrote:@Joanne Neal
would you mind retrying? I'll wait for the thread starter's response

I ran this code and it printed out true, but that's an invalid password.
 
andi miami
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all... sorry for the delayed reponse... I had to drive out of town for my job and I just got to my destinantion. Ok, so I will test what y'all responded with and let you know. Thanks!
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Report post to moderator
I edited the temp. solution. Please tell me if it works.

For one final time, can you tell us what are all characters that are not allowed?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48957
60
  • Mark post as helpful
  • send pies
  • Report post to moderator
Harsha Smith wrote:I edited the temp. solution. . . .
Don’t. I have told you not to do that before. I shall reopen this thread when I get a PM with the exact changes you made, so I can undo them.
 
    Bookmark Topic Watch Topic
  • New Topic