Previous topic | Next topic

Documentation / Regular Expressions / Backreferences \1

Backreferences \1

Backreferences match the previously captured subexpression. Subexpressions are marked with parentheses and numbered from 1 to 9. Use \1 to refer to the leftmost subexpression, \2 to refer to the second subexpression, and so on.

(\d+) \1 Find two equal numbers with space between them (e.g., 123 123)
\<(\w+) \1\> Find repeating words (e.g., the the)
<a href=("|')http://[^'"]+\1> An external link (in single or double quotes)

Previous topic | Next topic