Regex to match alphanumeric and spaces?

Just a FYI string clean = Regex. Replace(q, @"^a-zA-Z0-9\s", string. Empty); would actually be better like string clean = Regex.

Replace(q, @"^\w\s", string. Empty).

I got it: string clean = Regex. Replace(q, @"^a-zA-Z0-9\s", string. Empty); Didn't know you could put \s in the brackets.

Your regex will only match strings which do not contain alpha numerics, numbers or spaces. The ^ at the start of a means "not anything inside here" – JaredPar Oct 8 '08 at 4:56 That's exactly what I want. In the Regex.

Replace, I want to match anything that's NOT a letter, number or space. – John Sheehan Oct 8 '08 at 4:58 Ah okay, clearer now. – JaredPar Oct 8 '08 at 5:04.

I suspect ^ doesn't work the way you think it does outside of a character class. What you're telling it to do is replace everything that isn't an alphanumeric with an empty string, OR any leading space. I think what you mean to say is that spaces are ok to not replace - try moving the \s into the class.

You're right, that's starts with (which I knew, but it's late) – John Sheehan Oct 8 '08 at 4:38.

There appear to be two problems. You're using the ^ outside a which matches the start of the line You're not using a * or + which means you will only match a single character. I think you want the following regex @"(^a-zA-Z0-9\s).

– zigdon Oct 8 '08 at 4:39 Regarding #2, the quantifier doesn't really matter as he wants to replace all non-matching characters in the string rather than just a single run of them, which requires a global replace (.../g in Perl, not sure of the C# syntax), with or without the */+. – Dave Sherohman Oct 8 '08 at 13:31.

This: clean = Regex. Replace(dirty, "^a-zA-Z0-9\x20", String. Empty) \x20 is ascii hex for 'space' you can add more individual characters that you want to be allowed.

If you want for example "? " to be ok in the return string add \x3f.

The circumflex inside the square brackets means all characters except the subsequent range. You want a circumflex outside of square brackets.

Yeah, I want it inside. Match anything that isn't these character ranges – John Sheehan Oct 8 '08 at 4:42 Oh, where you said "I want" I thought you meant you wanted a regular expression to match that. You meant you want the result of Replace to be that.So you want the regular expression to not match that.

My brain hurts. – Windows programmer Oct 8 '08 at 4:53.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions