-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREGEX_Using_the_Test_Method.js
More file actions
32 lines (25 loc) · 992 Bytes
/
REGEX_Using_the_Test_Method.js
File metadata and controls
32 lines (25 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Using the Test Method
Regular expressions are used in programming languages to match parts
of strings. You create patterns to help you do that matching.
If you want to find the word the in the string The dog chased the cat,
you could use the following regular expression: /the/.
Notice that quote marks are not required within the regular expression.
JavaScript has multiple ways to use regexes.
One way to test a regex is using the .test() method.
The .test() method takes the regex, applies it to a
string (which is placed inside the parentheses), and
returns true or false if your pattern finds something
or not.
let testStr = "freeCodeCamp";
let testRegex = /Code/;
testRegex.test(testStr);
The test method here returns true.
EXERCISE
Apply the regex myRegex on the string myString using the .test() method.
You should use .test() to test the regex.
Your result should return true.
*/
let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex.test(myString);