Skip to content

Instantly share code, notes, and snippets.

@unknownuser88
Created January 6, 2014 13:24
Show Gist options
  • Save unknownuser88/8282843 to your computer and use it in GitHub Desktop.
Save unknownuser88/8282843 to your computer and use it in GitHub Desktop.
match(regexp) Executes a search for a match within a string based on a regular expression. It returns an array of information or null if no match is found.
//match(regexp) //select integers only
var intRegex = /[0-9 -()+]+$/;
var myNumber = '999';
var myInt = myNumber.match(intRegex);
console.log(isInt);
//output: 999
var myString = '999 JS Coders';
var myInt = myString.match(intRegex);
console.log(isInt);
//output: null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment