end

Next lesson: Destructuring To the next lesson →

Lesson: Capture groups in regular expressions Repeat

Do you speak JavaScript?

§ Capture groups in regular expressions

In this video lesson, you will learn how to use capture groups in regular expressions to match and extract specific pieces of information from strings in JavaScript.

Capture groups in JavaScript allow you to match and extract specific pieces of information from strings or arrays. They are a powerful tool for working with data and can be used to simplify and streamline your code.

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 bob@example.com and use this regular expression, the group (\S+\.\S+) will match example.com.

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.

questionnaire

Practice

Practice is the fastest way to learn knowledge permanently. I have prepared a small task for you related to the lesson.

Practice
discussion

Materials

Materials related to the lesson:
Files associated with the lesson

Materials

Next: Destructuring(02:59)

To the lesson →