All Tracks/regular expressions/
Đang tải...
Hướng dẫn thử thách
1 / 33

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. ```js let testStr = "freeCodeCamp"; let testRegex = /Code/; testRegex.test(testStr); ``` The `test` method here returns `true`. # --instructions-- Apply the regex `myRegex` on the string `myString` using the `.test()` method.
Vượt qua bài kiểm tra hiện tại để mở khóa bài tiếp theo.
main.js
UTF-8 • Tab Size: 2Kiểm tra bài:⌘↵
Test Output
Thử thách này không có bài test tự động. Hãy quan sát kết quả trực tiếp ở khung Preview.