473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

regex problem

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
Apr 10 '07 #1
6 1800
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);

"Frank" wrote:
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
Apr 10 '07 #2
It's been said that if you use a regular expression to solve a problem, you
then have two problems.

///ark
Apr 10 '07 #3
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

"Mark Wilden" <mw*****@communitymtm.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
It's been said that if you use a regular expression to solve a problem,
you then have two problems.

///ark

Apr 11 '07 #4
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.
Apr 11 '07 #5
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

"Mark Wilden" <mw*****@communitymtm.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>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.

Apr 11 '07 #6
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

"Mark Wilden" <mw*****@communitymtm.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>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.

Apr 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
6
by: Talin | last post by:
I've run in to this problem a couple of times. Say I have a piece of text that I want to test against a large number of regular expressions, where a different action is taken based on which regex...
16
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string)...
7
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.