Containing characters but not in specific order

usur

Newcomer
Joined
Jan 10, 2005
Messages
4
Im trying to parse the following
"Someword, another. SD-FR1 more WORDS"
And i would like to capture the "SD-FR1" part.
I know it consists only of capital letters, numbers or "-".
I also know that it contains at least one capital letter and one number but not in what order. It should work on
"Someword, another. S1R more WORDS" capturing "S1R" aswell.

Anyone know how to do this with .NET RegEx?

I've read and googled but havn't found any examples where you dont know the order of what you're searching for.

Thanx for your time

Fredrik Högberg
 
Clarification

usur said:
Im trying to parse the following
"Someword, another. SD-FR1 more WORDS"
And i would like to capture the "SD-FR1" part.
I know it consists only of capital letters, numbers or "-".
I also know that it contains at least one capital letter and one number but not in what order. It should work on
"Someword, another. S1R more WORDS" capturing "S1R" aswell.

Anyone know how to do this with .NET RegEx?

I've read and googled but havn't found any examples where you dont know the order of what you're searching for.

Thanx for your time

Fredrik Högberg

To clarify, you are wanting to find patterns of the form:

1) a word (with whitespace of other word separators on either side) <AND>
2) containing at least one capital letter AND one number <AND>
3) possibly containing a "-" character <AND>
4) containing no other characters EXCEPT the above
 
Yes, That's exactly what i want.
Can you help me?

I could do it in three steps but i'm trying to figure this regex thing out and would like to know if it's possible to do it in a one step expression

Fredrik
 
This should work

usur said:
Yes, That's exactly what i want.
Can you help me?

I could do it in three steps but i'm trying to figure this regex thing out and would like to know if it's possible to do it in a one step expression

Fredrik

This should work:

[ \t\r\n][\-A-Z0-9][\-A-Z0-9]+[ \t\r\n]

Note that the [ \t\r\n] contains a space as the first character in the brackets.

This expression says:

Find a character that is one of the following: space, tab, carriage return or linefeed
followed by a character that is a dash "-", uppercase letter or number
followed by one or more of the same
followed by character that is one of the following: space, tab, carriage return or linefeed

There is a special Unix regex expression "\W" that means a non-word character. You may be able to use that instead of the [ \t\r\n] but it didn't work as well as I liked in my text editor.

Note: You will be responsible for removing the leading and trailing space, tab, carriage return or linefeed when you find a matching instance.

Please let me know if this works for you or you have further questions. :)
 
Not quite

You're forgetting the
2) containing at least one capital letter AND one number <AND>
Your example matches 1111 as well as WORD, 1-1 or W-W.
 
I haven't forgot about you

usur said:
You're forgetting the
2) containing at least one capital letter AND one number <AND>
Your example matches 1111 as well as WORD, 1-1 or W-W.

Just wanted to let you know that I haven't forgot about you. In my spare time I am still thinking about your response, in which you are entirely correct. :cool:

I love regex's and this problem is really cool to solve.
 
Richard Crist said:
Just wanted to let you know that I haven't forgot about you. In my spare time I am still thinking about your response, in which you are entirely correct. :cool:

I love regex's and this problem is really cool to solve.

I found this at regexlib.com
Think it could be usefull but havn't really figured out how it works.

Expression: ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{4,8}$

Description: Password expresion that requires one lower case letter, one upper case letter, one digit, 6-13 length, and no spaces. This is merely an extension of a previously posted expression by Steven Smith (ssmith@aspalliance.com) . The no spaces is

You might understand it.
 
<Keanu Reeves Matrix voice> Whoa

usur said:
I found this at regexlib.com
Think it could be usefull but havn't really figured out how it works.

Expression: ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{4,8}$

Description: Password expresion that requires one lower case letter, one upper case letter, one digit, 6-13 length, and no spaces. This is merely an extension of a previously posted expression by Steven Smith (ssmith@aspalliance.com) . The no spaces is

You might understand it.

The above expression is very interesting. I have used regex's for some time now, but it appears that I have some more to learn. I went to the regexlib.com site and downloaded the "regulator". It looks to be an awesome tool. I will investigate this tool, comprehend the expression above and get back with you. Thank you for your post! It has lead me to a higher plane of regex existence. :)
 
Let's try again

usur said:
Yes, That's exactly what i want.
Can you help me?

I could do it in three steps but i'm trying to figure this regex thing out and would like to know if it's possible to do it in a one step expression

Fredrik

Try the expression below. I've tested it in my homemade .NET regular expression tester and it seems to work.

([ \t\r\n][A-Z]+[A-Z0-9\-]*[0-9]+[A-Z0-9\-]*[ \t\r\n])|([ \t\r\n][0-9]+[A-Z0-9\-]*[A-Z]+[A-Z0-9\-]*[ \t\r\n])

I'm tired now. :p
 
Back
Top