Regexdrill

Level 2: Groups and alternation Exercise 15 of 52 Pro

Backreference: doubled words

A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.

The task

A match anywhere counts. Match lines where the same whole word appears twice in a row, separated by one space, like the the.

What this exercise teaches

\b(\w+) \1\b captures a word, then requires a space and the identical text again, with word boundaries on both ends.

A hint if you get stuck

\1 matches the same text that group 1 captured. Use \b so that the and then are not treated as the same word.

This exercise is part of Pro

Pro unlocks all 52 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Groups and alternation