Skip to content

Instantly share code, notes, and snippets.

@craigsdennis
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigsdennis/9b31220fa32c6b137c83 to your computer and use it in GitHub Desktop.
Save craigsdennis/9b31220fa32c6b137c83 to your computer and use it in GitHub Desktop.
Regular Expression example in JavaScript
var title = "Regular Expressions in 10 different languages";
// This will be true or false
var result = /.*\d+.*/.test(title);
var match = /(\d+)/.exec(title);
if (match) {
console.log("There are ", match[1], " languages represented.");
}
// Strings also have a match. This is synonymous with the above.
var match = title.match(/(\d+)/);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment