November 2014
Beginner
336 pages
10h 58m
English
Regular expressions do nothing without a string to test them on. Let’s start with a simple string and a simple regular expression. Open the Chrome Dev Tools on any page, and create a string with your name in it; then create a regular expression with your name in it. See Listing 6.2.
Listing 6.2 My Name As a Regular Expression
> var myName = 'Steven Foote'; "Steven Foote"> var namePattern = /Steven/; /Steven/
Now you need to test whether the string matches the regular expression. You can do this in a few different ways, each with a slightly different purpose and output.
test returns a Boolean, true if the string matches and false if it doesn’t.
exec either returns an ...
Read now
Unlock full access