To use capture groups, you can use parentheses in your regular expression to enclose the pattern that you want to match. For example, the following regular expression uses capture group to match the second part of an email:
/\S+@(\S+\.\S+)/g email.replace(/\S+@(\S+\.\S+)/g, '...@$1')
If we have
firstname.lastname@example.org and use this regular expression, the group
(\S+\.\S+) will match
Capture groups are a useful feature of regular expressions and can be used to extract specific pieces of information from text in a concise and efficient way.
Practice is the fastest way to learn knowledge permanently. I have prepared a small task for you related to the lesson.
Materials related to the lesson:
→ Files associated with the lesson