Last active
August 29, 2015 14:21
-
-
Save craigsdennis/9b31220fa32c6b137c83 to your computer and use it in GitHub Desktop.
Regular Expression example in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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