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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Help with a RegEx?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Try this code...hope it helps

 
lowercase baba
Posts: 13086
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Marshal
Posts: 77544
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 77544
372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bring out your dead! Or a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
    Bookmark Topic Watch Topic
  • New Topic