From the course: Learning Regular Expressions

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Captures and backreferences

Captures and backreferences

- [Instructor] In this chapter, we will learn about capturing and how to use backreferences as to access the captures. In chapter five, we talked about grouping expressions with parentheses. Whenever you group an expression, the regex engine also captures it by default. It stores whatever text matches the grouped expression in memory for later use. Let's say we have a regex that starts with a, then inside parentheses ppl and then e at the end. Obviously it will match apple, but at the same time, the regex engine will capture ppl and remember it for later. It stores the actual data that was matched, not the expression. For example, if the parentheses had an expression to match either ppl or ngl, it would match angle and capture ngl or it would match apple and capture ppl. It doesn't matter if you were using these parentheses for repetition, for alternation, or just for your own organization. The regex engine will…

Contents