The pattern ^([a-z]*)<[A-Z]*>\1$
will match these strings (as seen on rubular.com):
ab<XYZ>ab
<XYZ>
bleh<FOO>bleh
<>
It will not match these:
ab<XYZ>de
x<XYZ>y
FOO<foo>FOO
That is, the pattern is something like
tag
<CONTENT>
tag
The same tag
appears for both the "prefix" and the "suffix". Tag consists of zero or more lowercase letters. Content consists of zero or more uppercase letters. The prefix part is matched and captured by group 1, and then a backreference \1
is used to match that string again for the suffix.
The […]
is a character class. Something like [aeiou]
matches one of any of the lowercase vowels. [^…]
is a negated character class. [^aeiou]
matches one of anything but the lowercase vowels.
As a Java string literal, the pattern is "^([a-z]*)<[A-Z]*>\\1$"
.