(a*)X\1
Regular Expression | |||
String | |||
Group 0 | |||
Group 1 | Group 2 | Group 3 | Group 4 |
The applet searches for substrings that match the regular expression. The regular expression does not have to match the complete string The expression
(a*)X\1
searches the string
aaaaaaaaaaaaXaaa
and finds the match
aaaXaaa
(a*)
greedily matches as much as it can
without preventing the complete expression from matching.
But this means that it
can only match aaa immediately preceeding 'X'.
If (a*)
matched as much as it possibly could,
then \1
would not match the final aaa of the string.
Write a regular expression that matches strings that begin with three alphabetic letters (upper or lower case), contain any number of alphabetic letters in the middle (upper or lower case), and end with the same three letters they start with, but in reverse order.
For example, abcWHATISTHISSTUFFcba and XyZmoreandmoreZyX are acceptable strings.