473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

regular expressions. Order matters?

Hello.

I am trying to create a regular expression that will let me know if a string
has the following criteria. Order does not matter in the string, but when
building a regular expression it does, right? I am brand new to regular
expressions and having a little (read: a lot of) difficulty in making a
regular expression that makes sure the string meets the following rules.

The string contains at least one character from two of the following four
sets.
- an uppercase alpha character
- a lowercase alpha character
- a digit
- a punctuation mark (IE: , . ; ' " ! ?)

The problem that I am having is that order matters in the regular expression
but it does not matter in my string. Any thoughts or references that might
help me out a little?

Thanks in advance for you help.
Ryan Taylor
Nov 16 '05 #1
3 2132
sure, apply four different regular expressions. If more than two of them
match, you are good to go.

Don't create an overly complex regex for a password algorithm.

--- Nick

"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:uX*************@TK2MSFTNGP12.phx.gbl...
Hello.

I am trying to create a regular expression that will let me know if a string has the following criteria. Order does not matter in the string, but when
building a regular expression it does, right? I am brand new to regular
expressions and having a little (read: a lot of) difficulty in making a
regular expression that makes sure the string meets the following rules.

The string contains at least one character from two of the following four
sets.
- an uppercase alpha character
- a lowercase alpha character
- a digit
- a punctuation mark (IE: , . ; ' " ! ?)

The problem that I am having is that order matters in the regular expression but it does not matter in my string. Any thoughts or references that might
help me out a little?

Thanks in advance for you help.
Ryan Taylor

Nov 16 '05 #2
Yes, order does matter in a Regex. And it can be of use.
For instance, I have a program that wants to find words in some text, and
match them against a word list. The only snag is, I don't want to match any
that are enclosed in square brackets. So, instead of just having the regex
"\w+"
I have
"\[\s*\w+\s*]|\w+" ( end square brackets ']' don't need escaping)
That way, if it can enclose the word in square brackets, it will. And since
the square brackets aren't included in the words in the list I'm checking
against, in that case it won't match. But if there is a word that isn't in
square brackets, then it will match the bit to the right of the pipe, which
has a chance of being in the word list. But I know that if it matches the
"\w+" bit, then it obviously didn't match the word-in-square-brackets bit,
and thus hasn't got square brackets round it.

"Ryan Taylor" wrote:
Hello.

I am trying to create a regular expression that will let me know if a string
has the following criteria. Order does not matter in the string, but when
building a regular expression it does, right? I am brand new to regular
expressions and having a little (read: a lot of) difficulty in making a
regular expression that makes sure the string meets the following rules.

The string contains at least one character from two of the following four
sets.
- an uppercase alpha character
- a lowercase alpha character
- a digit
- a punctuation mark (IE: , . ; ' " ! ?)

The problem that I am having is that order matters in the regular expression
but it does not matter in my string. Any thoughts or references that might
help me out a little?

Thanks in advance for you help.
Ryan Taylor

Nov 16 '05 #3
I have made a number of smaller regular expressions and checked them each
individually to ensure that the string passes the rule check. This was
definately much easier than trying to create a super expression that would
check everything at once.

Thanks again.
Ryan Taylor
Nov 16 '05 #4

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

Similar topics

5
2701
by: DjDrakk | last post by:
I want to use headers to redirect the client if they didn't come from the correct page, but I have a problem with one page. If they leave a form field empty, they are redirected back to the page...
7
2577
by: YoBro | last post by:
Hi I have used some of this code from the PHP manual, but I am bloody hopeless with regular expressions. Was hoping somebody could offer a hand. The output of this will put the name of a form...
2
2624
by: robert kurz | last post by:
hallo ng, i am trying to parse a sql-statement with regular expressions. my goal is to get the parts of the statement. in my thoughts the group-functionality of the regular expressions should do...
7
3794
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
2271
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
13
2187
by: blair.bethwaite | last post by:
Hi all, Does anybody know of a module that allows you to enumerate all the strings a particular regular expression describes? Cheers, -Blair
25
5128
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
4
1306
by: Dabbler | last post by:
I'm trying to parse the title and url out of a bunch of menu javascript statements to convert a Macromedia menu to ASP.NET menu control. The line I'm searching is of the form:...
3
2734
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
0
7199
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
7076
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...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
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
5576
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,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.