Containing characters but not in specific order

usur

New member
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?

Ive read and googled but havnt found any examples where you dont know the order of what youre searching for.

Thanx for your time

Fredrik H
 
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?

Ive read and googled but havnt found any examples where you dont know the order of what youre searching for.

Thanx for your time

Fredrik H
 
Yes, Thats exactly what i want.
Can you help me?

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

Fredrik
 
This should work

usur said:
Yes, Thats exactly what i want.
Can you help me?

I could do it in three steps but im trying to figure this regex thing out and would like to know if its 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 didnt 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

Youre 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 havent forgot about you

usur said:
Youre 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 havent forgot about you. In my spare time I am still thinking about your response, in which you are entirely correct. :cool:

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

I love regexs and this problem is really cool to solve.

I found this at regexlib.com
Think it could be usefull but havnt 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 havnt 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 regexs 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. :)
 
Lets try again

usur said:
Yes, Thats exactly what i want.
Can you help me?

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

Fredrik

Try the expression below. Ive 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])

Im tired now. :p
 
Back
Top