Some pretty basic questions regarding regexp's

Hi,

I'm using this regexp with preg_match:

"/^(\D*\d\D*){1,3}$/"

to determine if a string contains minimum 1 maximum 3 numbers in it. (For a new, user-entered password)
It seems to work, but I was wondering if this is right and/or this could be done more easy!

I also want to check if a character (a-z, A-Z) was not entered more then 3 times subsequently (Donno how to say it correctly in english :-) )
Like rTaaaa12 -> the "aaaa" should make the pass invalid.

If anyone has suggestions/links to existing password validation regexp's, they could be usefull too offcourse.

Any help appreciated!
mrjoeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

inq123Commented:
Hi mrjoe,

that's correct and I'm afraid it can't be simpler than that.  For 'aaa' or longer, I wrote this regex for you (verified it and it works well):

/(.)(?=\1{2,})/

Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
inq123Commented:
just noticed that you don't want a char to be more than 3 times, then use this regex:

/([a-zA-Z])(?=\1{2,})/
0
mrjoeAuthor Commented:
I'm having problems with your regexps, and with my other regexps in general. See when I try your first regex:

/(.)(?=\1{2,})/       it doesn't work.

I looked through the php manual and understand completely (I think =) ) what you are doing, but some things just don't seem to work with me :/

When I try to simplify the expression in order to find anything wrong and I try this:

/(a)(?=a{2,})/

..then this works, matches 'aaa' or longer.

But /([a-zA-Z])(?=\1{2,})/   or /(\D)(?=\1{2,})/ won't work either...

How come this backreferencing with \1 is not working? And I get the impression that sometimes other things that won't work, are actually right and should work. What could there be wrong? Any help greatly appreciated, I'm getting curious about this problem. Points slightly increased too.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

inq123Commented:
My regex definitely works as I tried both in Perl and PHP.  The only reason why it doesn't work my guess would be that your php version is too low to support lookahead regex (or rather, the \1 back reference?).  Try $1 if that doesn't work, since in php there's a move away from \1 to $1 since old syntax was always \1 but newer php it's $1.  So this might be a problem if your php is too new.  But my php's rather new too (4.3.3) and also php was trying to move closer to perl (it's using PCRE) so because Perl's still using \1, php should too.  But it doesn't hurt to try.

Nothing against you at all, but I feel rather frustrated that simple Q/A like this one would always go wrong, and it always has something to do with OS, version of the interpreter, or user execution.  Wouldn't it be nice that every software has only one version and all OS are the same? :-)
0
mrjoeAuthor Commented:
Wouldn't that be something :-)

And since indeed your regex's look perfectly right to me, and it's a personal problem here, the points are yours.

Thanks for your help.
0
inq123Commented:
Thanks for the points and I do want to help you solve this!  So please let me know if $1 works for you, and maybe let me know what other problem you have with your regex in general?  Would that give a little clue? (desperately looking for clue here ... :-) )
0
mrjoeAuthor Commented:
Very nice of you :-)

$1 didn't work, upgrading my local php server (did had an old pcre lib :/ ) didn't worked either, but then... I tried ' instead of " for the pattern string.....

preg_match('/(.)(?=\1{2,})/',$pass) instead of preg_match("/(.)(?=\1{2,})/",$pass)

This works! Offcourse, I can also just add an extra backslash ( \\1 instead of \1 ) for it to work.

*shame* why didn't I think of this earlier! But these are my first steps with regexp's :p

But since this was a problem, I guess that most of you always use ' ? At the moment, I find it strange I found so much examples with " since you probably have to escape more characters.

Thanks again for helping me out with this, I'm happy it works now :-)
0
inq123Commented:
I see.  For some reason, if I didn't see preg_match("/regex/", $somestring) then I never think of the problem of " or '.  Should've thought of that earlier.  I'm on a different computer now, so I can't check why it worked for me on php, I must have done something almost subconciously.  But on perl, there's no complication like this as quote is not needed.

Anyway glad it finally worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.