-2

i need a regular expression that check a string for any non-standard ASCIi characters.

3
  • 1
    Could you clarify what you mean by "non-standard"? (And for that matter, what you mean by "ASCII". Normally by "ASCII characters" people mean from 00 to 7F, but there's some variation.)
    – ruakh
    Jan 10, 2012 at 17:53
  • 1
    There are no "non-standard" ASCII characters. ASCII (codepoints 0x00-0x7F) is pretty well standardized. Anything at codepoint 0x80 or higher isn't ASCII, by definition Jan 10, 2012 at 18:07
  • I think the sensible way to interpret the question is: non-(standard ASCII characters), not (non-standard) (ASCII characters). Though the wording can be misinterpreted by some, I think this is a fine question. It helped me.
    – MattD
    Jan 2, 2014 at 18:45

3 Answers 3

4

You can specify character's unicode point in c# string: "[\u0080-\uFFFF]" should find any character whose "ascii" code is 128+

1

does this simple one suit your needs ? [^\x20-\x7E]

1
  • I like this one best, although, I needed to add "\t\n\r" to skip some of the standard whitespace.
    – mfras3r
    Jun 16, 2015 at 13:04
0

Put what you consider the standard characters in a set, then put the negate ^ sign in the set. That will match the nonstandard. For example I consider the standard to be a-z so my nonstandard match pattern would be

[^A-Za-z]

if that matches you have a non standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.