Creating Regular Expressions
Let's say we have the following string:
How many boards would the Mongols hoard, if the Mongol hordes were bored?[1]
[1] Bonus points if you know where this quote is from: email me at advjs@wire-man.com.
And let's say we have the following regular expression:
var myRegExp = /mongol/
How do we know we've created a regular expression? The clue is the forward slashes before and after the pattern, right where you'd expect quotes to be.
So we have the pattern “mongol.” Does this pattern match anything in the string? Actually, no. Regular expressions are case-sensitive, and while “Mongol” occurs twice in the text, “mongol” ...
Get Advanced JavaScript™: Insights and Innovative Techniques now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.