Skip to content

Instantly share code, notes, and snippets.

@piscis
Created December 12, 2011 09:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piscis/1466115 to your computer and use it in GitHub Desktop.
Save piscis/1466115 to your computer and use it in GitHub Desktop.
Match ASCII chars via RegularExpression in Javascript
/**
* Small regular expression to match ASCII-chars between 32-126
*
* For a conversion table for ASCII chars see:
* http://de.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange
*/
var expr = /([\x20-\x7E]{1,})/gi;
var testString = "Foo Bar Barz";
var testString2 = "Foo Bar\tBarz";
// Test
console.log(testString.match(expr)[0]===testString); // is true;
console.log(testString2.match(expr)[0]===testString2); // is false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment