# Regular expression for the second symbols from the front and the back are equal

I am practicing for an exam. I am trying to convert a language to a regular expression. The language and my solution is as follows:

$L=\{w∈\{a,b\}^+│|w|≥4\ and\ the\ second\ symbols\ from \ the \ front\ and\ the\ back\ are\ equal\}$

Solution: $(a+b)x(a+b)^* x(a+b) \ \ where\ x=(a+b)$

Is this correct? If not, can someone correct me. also, am I allowed to use variables in regular expressions?

• I think the definition of $L$ is unclear. Is $aabb \in L$?
– Raphael
Jun 15 '17 at 12:47
• @Raphael No, it is not Jun 15 '17 at 12:55
• So, $L = \{ wvw \mid x, w \in \{a,b\}^2, |w| = 2 \}$? Then, the easiest (if maybe not fastest) route is probably to come up with an NFA and convert it.
– Raphael
Jun 15 '17 at 13:26
• Regarding your attempt, if your notation means to imply that $x$ "matches" the same string, it's not a regular expression. If that was not the intent, then the regular expression matches $abba$ which is not in $L$.
– Raphael
Jun 15 '17 at 13:27
• @AndréSouzaLemos Oh, right. In that case, I understand the attempt -- but it's not a regular expression. Amine, you may have regexps with capturing groups in mind, as they are encountered in programming libraries. Those are strictly more powerful than regular expressions as defined in TCS.
– Raphael
Jun 15 '17 at 21:08