A regular expression to match all characters on the US keyboard.

I am looking for a regular expression pattern to match all characters that are on the US keyboard. right now, I only match letters and numbers and a space, so it looks like

^[a-zA-Z0-9\\s]+$ 

But now I need it to match any character found on the keyboard. I even want it to match if the string is also empty.

+6
regex
source share
1 answer
  ^[\x00-\x7F]*$ 

for 0-n ASCII characters

  ^[\x20-\x7F]*$ 

will be more accurate, as mentioned by Nick D. in the comment: from SPACE to DEL .

As described in detail in regular-expressions.info :

\ xFF, where FF are two hexadecimal digits

Matches a character with the specified ASCII / ANSI value, which depends on the codepage used. Can be used in character classes.

[\x20-\x7F] is a character class that defines a range of characters here.

+8
source share

All Articles