Thread: C# основной форум/Regular expressions

Regular expressions
How to: Strip Invalid Characters from a String

String CleanInput(string strIn)
        // Replace invalid characters with empty strings.
        return Regex.Replace(strIn, @"[^\w\.@-]", "");

The regular expression "^[0-9]*$" only matches strings that consist entirely of digits.

Othe useful expressions:
{n,} - matches at leas n times
{n,}? - nongreedy {n,} quantifier
\s - only spaces

Allowing only single space in between two words


This Regular expression will simply not allow more than a single space to be entered between two words of a sentence.It will also prohibit user to enter space at the begining and at the end of a sentence.It will require a minimum of 2 alphabets for making it a valid expression.

For any words+digits:


The 30 Minute Regex Tutorial

In Russian language

Re: Regular expressions