6

I'm looking for a regex pattern to match all characters that are found on a U.S. keyboard. right now, I match only on letters and numbers and white space, so it looks like

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

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

Tomalak
  • 332,285
  • 67
  • 532
  • 628
Shafique
  • 1,828
  • 6
  • 26
  • 36

1 Answers1

10
  ^[\x00-\x7F]*$

for 0-n ASCII characters

  ^[\x20-\x7F]*$

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

As detailed in regular-expressions.info:

\xFF where FF are 2 hexadecimal digits

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

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

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250