This is not a good regex task - it isn't strictly pattern matching, it's a counting job, which regex is pretty bad at.
While you can do it it would be horribly complex, and if you decided at a later date that you wanted to include special characters in there it would be a real PITA to maintain.
Instead, do it in code: Use two regexes - one to return all the digits, and one to return all the alpha characters. You then check that the length of both is greater than zero.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
The best suggestion I have is to find (or invent) some interesting problems, then play with Expresso to solve them (in as many ways as you can think of).
Having said that, remember that regex is not the universal solution for string processing. There are many cases where regex is not the appropriate tool.
(Remember the old saw "When all you have is a hammer, everything looks like a nail." Don't let regex become your hammer.)
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
i am doing a project, i want to match a string with regex which will match the whole string and it dosent allow two white spaces concerrently on after the other and also it dosent allow white spaces at starting and ending of string, any number of white spaces is allowable but not concurrently one after the other
I want to:
1) count the number of round brackets '(', I expect as result 2
2) get the text inside, I expect "\"Happy"\", which appear in console output as "Happy"
No idea for 1. I try the following for 2
string k = Regex.Match(s1,@"\((\w+)\)").Groups.Value;
But It fails in understanding the \" character