Regex (Java / .NET) / Retina, 43 bytes
Try it online! - Java (very slow)
Try it online! - Regex (.NET)
Try it online! - Retina
Regex (Pythonregex / .NET) / Retina , 47 bytes
(?=((3円x+?|^x)(?<=(?=2円+$)^.*(2円)))+)(2円x+)4円+$
Try it online! - Python import regex
Try it online! - .NET
Try it online! - Retina
This is a port of the 43 byte Java/.NET version, avoiding a nested backreference in order to add Pythonregex support. The way in which this is done (placing the copy inside the lookbehind) removes Java support.
Regex (Perl / PCRE2 v10.35+), 49 bytes
Try it online! - Perl (slow)
Attempt This Online! - PCRE2 v10.40+
(?=
(
(2円x+?|^x)
((?<= # (?3) calls this
(?= # Circumvent the constant-width limitation of lookbehinds
# in PCRE by using a lookahead inside the lookbehind
^2円+$ # This is the payload of the emulated variable-length
# lookbehind, same as the one in the .NET regex
|
(?3) # Recursive call - this is the only alternative that can
# match until we reach the beginning of the string
)
. # Go back one character at a time, trying the above
# lookahead for a match each time
))
)+
)
(2円x+)
4円+$
Regex (Java / Pythonregex / .NET) / Retina , 50 bytes
(?=((?=(3円|^))(2円x+?)(?<=(?=3円+$)^.*))+)(3円x+)4円+$
Try it online! - Java (very slow)
Try it online! - Python import regex
Try it online! - .NET
This is a port of the 43 byte Java/.NET version, avoiding a nested backreference in order to add Pythonregex support, while keeping Java support.
Regex (Perl / PCRE), 58 bytes
Try it online! - Perl (slow)
Try it online! - PCRE1
Try it online! - PCRE2 v10.33
Attempt This Online! - PCRE2 v10.40+
Regex (.NET) / Retina, 43 bytes
Try it online! - Regex (.NET)
Try it online! - Retina
Regex (PCRE2 v10.35+), 49 bytes
Attempt This Online! - PCRE2 v10.40+
(?=
(
(2円x+?|^x)
((?<= # (?3) calls this
(?= # Circumvent the constant-width limitation of lookbehinds
# in PCRE by using a lookahead inside the lookbehind
^2円+$ # This is the payload of the emulated variable-length
# lookbehind, same as the one in the .NET regex
|
(?3) # Recursive call - this is the only alternative that can
# match until we reach the beginning of the string
)
. # Go back one character at a time, trying the above
# lookahead for a match each time
))
)+
)
(2円x+)
4円+$
Regex (PCRE), 58 bytes
Try it online! - PCRE1
Try it online! - PCRE2 v10.33
Attempt This Online! - PCRE2 v10.40+
Regex (Java / .NET) / Retina, 43 bytes
Try it online! - Java (very slow)
Try it online! - Regex (.NET)
Try it online! - Retina
Regex (Pythonregex / .NET) / Retina , 47 bytes
(?=((3円x+?|^x)(?<=(?=2円+$)^.*(2円)))+)(2円x+)4円+$
Try it online! - Python import regex
Try it online! - .NET
Try it online! - Retina
This is a port of the 43 byte Java/.NET version, avoiding a nested backreference in order to add Pythonregex support. The way in which this is done (placing the copy inside the lookbehind) removes Java support.
Regex (Perl / PCRE2 v10.35+), 49 bytes
Try it online! - Perl (slow)
Attempt This Online! - PCRE2 v10.40+
(?=
(
(2円x+?|^x)
((?<= # (?3) calls this
(?= # Circumvent the constant-width limitation of lookbehinds
# in PCRE by using a lookahead inside the lookbehind
^2円+$ # This is the payload of the emulated variable-length
# lookbehind, same as the one in the .NET regex
|
(?3) # Recursive call - this is the only alternative that can
# match until we reach the beginning of the string
)
. # Go back one character at a time, trying the above
# lookahead for a match each time
))
)+
)
(2円x+)
4円+$
Regex (Java / Pythonregex / .NET) / Retina , 50 bytes
(?=((?=(3円|^))(2円x+?)(?<=(?=3円+$)^.*))+)(3円x+)4円+$
Try it online! - Java (very slow)
Try it online! - Python import regex
Try it online! - .NET
This is a port of the 43 byte Java/.NET version, avoiding a nested backreference in order to add Pythonregex support, while keeping Java support.
Regex (Perl / PCRE), 58 bytes
Try it online! - Perl (slow)
Try it online! - PCRE1
Try it online! - PCRE2 v10.33
Attempt This Online! - PCRE2 v10.40+
This is not just the shortest, but the fastest under RegexMathEngine, even though the 43 byte .NET regex it's based on is the slowest under .NET (beaten by both 44 byte regexes in speed).
As far as speed goes, the smallest-to-largest version is faster than the largest-to-smallest version (both in .NET and their ports below). Both are faster than the 43 byte version under .NET.
This is a port of the secondlargest-to-smallest 44 byte .NET regex, using lookinto instead of variable-length lookbehind. Although the Perl/PCRE syntax for lookahead conditionals is more verbose, this is compensated for by being able to use a possessive quantifier.
This is a port of the firstsmallest-to-largest 44 byte .NET regex, again using lookinto instead of variable-length lookbehind. This one is less conducive to being ported, and I had to use (?^0=), lookinto accessing the in-progress current match. I've not decided how to finalize the current behavior of this, so it's likely this version will not work with a future version of lookinto.
This is a port of the second 44 byte .NET regex, using lookinto instead of variable-length lookbehind. Although the Perl/PCRE syntax for lookahead conditionals is more verbose, this is compensated for by being able to use a possessive quantifier.
This is a port of the first 44 byte .NET regex, again using lookinto instead of variable-length lookbehind. This one is less conducive to being ported, and I had to use (?^0=), lookinto accessing the in-progress current match. I've not decided how to finalize the current behavior of this, so it's likely this version will not work with a future version of lookinto.
This is not just the shortest, but the fastest under RegexMathEngine, even though the 43 byte .NET regex it's based on is the slowest under .NET (beaten by both 44 byte regexes in speed).
As far as speed goes, the smallest-to-largest version is faster than the largest-to-smallest version (both in .NET and their ports below). Both are faster than the 43 byte version under .NET.
This is a port of the largest-to-smallest 44 byte .NET regex, using lookinto instead of variable-length lookbehind. Although the Perl/PCRE syntax for lookahead conditionals is more verbose, this is compensated for by being able to use a possessive quantifier.
This is a port of the smallest-to-largest 44 byte .NET regex, again using lookinto instead of variable-length lookbehind. This one is less conducive to being ported, and I had to use (?^0=), lookinto accessing the in-progress current match. I've not decided how to finalize the current behavior of this, so it's likely this version will not work with a future version of lookinto.
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55
- 12.9k
- 2
- 71
- 55