CIS 111 Lecture Notes - Lecture 5: Whitespace Character, Newline, 7 Up
Regular Expressions (Wk 6)
• What We Will Cover in Class
o RegExp
o Window.addEventListener
• JavaScript Objects
Type
What it Does
Array
helps store, retrieve, and manipulate collection of data
Boolean
acts as wrapper around Boolean primitive; still very much in love w/ true / false
Date
allows you to more easily represent and work w/ dates
Function
allows you to invoke some code among other esoteric things
Math
nerdy one in group that helps you better work w/ numbers
Number
acts as wrapper around number primitive
RegExp
provides a lot of functionality for matching patterns in text
String
acts as wrapper around string primitive
• Learning Regular Expressions (RegExp)
o Regular expressions are a way to describe patterns in string data
o Form small, separate language that is part of JavaScript and other languages
o RegExp patterns are used with exec and test methods, and with match, replace,
search, and split String methods
• Creating RegExp
o Type of object
▪ Can be either constructed with RegExp constructor or written as literal value
by enclosing pattern in forward slash (/) characters
• let e=e RegEpjaa;
• let re2=/java/;
• e.testjaasipt;
• Testing for Matches
o RegExp objects have a number of methods. Simplest is test.
▪ If you pass it a string, it will return a Boolean telling you whether the string
contains a match of the pattern in the expression
Let re2=/java/;
Re.testjaasipt; //true
Re.testJaasipt; //false
/a/.testade; //true
/a/.testade; //false
• Matching set of Characters
//following expression matches all strings that contain a digit
let pattern=/[0123456789]/;
find more resources at oneclass.com
find more resources at oneclass.com