JS TutorialLesson 26Free preview
JS RegExp
This lesson is part of JavaScript · All levels
Summary
Regular expression (regex) is a character pattern for searching, checking, and changing text flexibly. In JavaScript, regex can be written literally as /learn/i or created with new RegExp(), and then used through method test, match, replace, and search. Flags like g (global) and i (case-insensitive) change matching behavior.
Key points
- Literal regex: /pattern/flags, for example /^[a-z]+$/i
- Test() return true/false, exec() check the details fit, replace() replace
- The g-flag matches all the appearances, the flag I ignore the big little letters
- Metacharacter like.*+?? and class characters [0-9] expand the pattern
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.