regex problem

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

Hello,
I have to admit, reg expres are not my thing, I'm having difficulties with
changing an expression. Could someone give me a hand?
I use
^\w*(?=\w*\d)(?=\w*[a-z!@#$%])(?=\w*[A-Z])\w{6,}$

to check a string for at least a lowercase letter, an uppercase and a digit
(password). I want to add the optional characters !@#$%(). What do I have to
change?

Thanks
Frank
 
Why use a regex - it's not that complicated...

int bitmap = 0;

foreach(char ch in str)
{
if (Char.IsLower(ch)) bitmap |= 1;
else if (Char.IsUpper(ch)) bitmap |= 2;
else if (Char.IsDigit(ch)) bitmap |= 4;
else if (ch == '!' || ch == '@' || ch == '#' || ch == '$' || ch == '%'
|| ch == '(' || ch == ')' || ch == '.') bitmap |= 8;

if (bitmap == 15) break;
}

return (bitmap == 15);
 
It's been said that if you use a regular expression to solve a problem, you
then have two problems.

///ark
 
If you use a screwdriver to hammer nails, you have a problem. If you use a
screwdriver to screw screws, you have a solution.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
I think the point of the comment is not that regular expressions are not the
right tool for some jobs, but that they're difficult to use.

I know that I use them so infrequently that I usually have to fire up
RegexBuddy to test the syntax.
 
I have also run into situations where Regex is very slow. I have used it a
lot, but am moving away from to because of speed issues.
Ethan
 
I almost ALWAYS use RegexBuddy to build Regular Expressions. But I also
always use Visual Studio to build .Net software. While I could build regular
expressions without a tool, and I can create small ones easily, using a tool
makes the process much faster and easier, and RegexBuddy is only $30.00
(last time I checked).

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Back
Top