How set regex back reference? With already set group?

^([a-z])+([ ])\1$

I think is works like:

Texthere space with \1 also allowed same as on set Group 1?

Result: test test <β€” not match

But it not really do any idea why?

Back reference is used for not repeat the rule if want to use later not?


This only captures a single letter (a-z). If you want multiple consecutive letters to be captured, the + should be inside the parentheses. Also, you do not need to capture the space between the two words. You just need to make sure your regex has a space character immediately after the first capture group and immediately before the back reference.

The following is not needed:

([ ])
1 Like

I try something:


But that also not mach the test test


Read my last reply again. You are missing the + and you do not have the space I mentioned.

1 Like


So this one?

now you are missing a space between the words
capture is not needed for space , but the space can’t miss

1 Like

So ^([a-z]+) \1$ But this mean is only match what entered before?
Like test test match but test notest is not? This is not the goal just able to write a-z in first and second after space any characters no need set same? That way why not work?

So the back reference is looking for same entered data with a-z not just for type?


when you use a capture group (with the round parens), what is matched is captured, and then when you use \1 it will match only the same thing matched by the capture group

1 Like