Regex code for 2 words that start with the same letter

How about this regex:

^(\w)\w*\s+\1\w*$

This regex check string contains only 2 words (In regex definition, word is \w metacharacter)
And the first character in first word is a capture group, and it is needed to repeat in the first character in second word.

Leave a Comment