CHANDRA
CHANDRA

Reputation: 4928

Issue with Regex in WPF?

private void TxtName_TextChanged(object sender, TextChangedEventArgs e)
    {
            string getString = Regex.Replace(TxtName.Text, @"[a-z, A-z, 0-9]", string.Empty);

    } 

with above code i can replace the string which is matching with the pattern @"[a-z, A-z, 0-9]". But what i need is , I want to replace the string which is not matching with the pattern @"[a-z, A-z, 0-9]".

Upvotes: 0

Views: 233

Answers (2)

Florent Vielfaure
Florent Vielfaure

Reputation: 126

If you want to match everything that is not a word, you can simply use the meta-character \W which is equivalent to [^A-Za-z0-9_].

Upvotes: 0

shift66
shift66

Reputation: 11958

Place a ^ in square braces. And also I think you should replace commas and make the second z uppercase @"[^a-zA-Z0-9]" this will match all non letters and digits.

Upvotes: 5

Related Questions