Regex (Perl / PCRE2 / Boost / Pythonregex
), 65 bytes
^(([losxz])((?1)\2|)|b(?1)q|q(?1)b|d(?1)p|p(?1)d|n(?1)u|u(?1)n|)$
Try it online! - Perl
Try it online! - PCRE2
Try it online! - Boost
This is a straight port of my Perl/PCRE2/Boost answer to Numbers with Rotational Symmetry.
^ # Assert this is the start of the string
( # Define (?1) recursive subroutine call
([losxz]) # \2 = match a char that is its own rotation
((?1)\2|) # Optionally match (?1) followed by \2
|
b(?1)q
|
q(?1)b
|
d(?1)p
|
p(?1)d
|
n(?1)u
|
u(?1)n
|
# Match an empty string at the center of an even-length string
)
$ # Assert this is the end of the string
(This works in the latest version of Pythonregex
, but not the one on TIO, and ATO doesn't have it installed.)
If there just one more matched pair of distinct characters, e.g. a
↔e
, another method would win by 3 bytes:
^(([losxz])((?1)\2|)|a(?1)e|e(?1)a|b(?1)q|q(?1)b|d(?1)p|p(?1)d|n(?1)u|u(?1)n|)$
^((?=([losxz]|a.*e|e.*a|b.*q|q.*b|d.*p|p.*d|n.*u|u.*n)(?<=(.))).((?1)\3|)|)$
But instead it loses by 1 byte:
^(([losxz])((?1)\2|)|b(?1)q|q(?1)b|d(?1)p|p(?1)d|n(?1)u|u(?1)n|)$
^((?=([losxz]|b.*q|q.*b|d.*p|p.*d|n.*u|u.*n)(?<=(.))).((?1)\3|)|)$
Regex (Ruby), 72 bytes
^((?=([losxz]|b.*q|q.*b|d.*p|p.*d|n.*u|u.*n)(?<=(.))).(\g<1>\k<3+0>|)|)$
Try it online!
In this port, unlike the Perl/PCRE2/Boost version, the alternative method wins by 5 bytes:
^(([losxz])(\g<1>\k<2+0>|)|b\g<1>q|q\g<1>b|d\g<1>p|p\g<1>d|n\g<1>u|u\g<1>n|)$
^((?=([losxz]|b.*q|q.*b|d.*p|p.*d|n.*u|u.*n)(?<=(.))).(\g<1>\k<3+0>|)|)$
Regex (.NET), 75 bytes
^((?=([losxz]|b.*q|d.*p|n.*u|p.*d|q.*b|u.*n)(?<=(.))).?)+(?<-3>\3)*(?(3)^)$
Try it online!
This is a straight port of my .NET answer to Numbers with Rotational Symmetry.
Regex (Perl / PCRE / .NET), 79 bytes
^((?=([losxz]|b.*q|q.*b|d.*p|p.*d|n.*u|u.*n)(?<=(.))).?(?=.*(\3(?(4)\4))))*\4?$
Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - .NET
Regex (Perl / PCRE / Java / .NET), 86 bytes
^((?=([losxz]|b.*q|q.*b|d.*p|p.*d|n.*u|u.*n)(?<=(.))).?(?=.*(\3(\6\4|(?!\6))())))*\4?$
Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Java
Try it online! - .NET
Regex (Perl / PCRE2 / Pythonregex
), 90 bytes
^(l(?1)l|o(?1)o|s(?1)s|x(?1)x|z(?1)z||b(?1)q|q(?1)b|d(?1)p|p(?1)d|n(?1)u|u(?1)n|[losxz]?)$
Try it online! - Perl
Try it online! - PCRE2
Try it online! - Python import regex
Unlike in Numbers with Rotational Symmetry, this comes in last place here. However, it's only with the old version of the mrab-regex Python module on TIO that this is needed. The 65 byte regex works in its latest version.