Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
explain what the shortest size would become without the /i flag
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

All of these regexes use their engines' respective case insensitivity flags, so that has not been counted towards the byte counts. Even though some use \pL (a shorthand for \p{L}) instead of [A-Z], they still need the flag, due to comparing characters via backreference. Without it, they would need to apply the flag inline, (?i) inserted at the beginning, costing 4 extra bytes.

All of these regexes use their engines' respective case insensitivity flags, so that has not been counted towards the byte counts. Even though some use \pL (a shorthand for \p{L}) instead of [A-Z], they still need the flag, due to comparing characters via backreference.

All of these regexes use their engines' respective case insensitivity flags, so that has not been counted towards the byte counts. Even though some use \pL (a shorthand for \p{L}) instead of [A-Z], they still need the flag, due to comparing characters via backreference. Without it, they would need to apply the flag inline, (?i) inserted at the beginning, costing 4 extra bytes.

the anchor was only implied in Python because I used the wrong regex call; and, differentiate between Python with and without "regex" module
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55

Regex (Perl 5 / PCRE / Boost / Python 3regex), 21🐌, 22🐌, 24, or 25 bytes

(?>.*?(\pL)(?!.*\1)){26} (24 bytes) -  

Try it on regex101 (PCRE1)
Try it online! (Python import regex)

Try it online! (Python 3) (24 bytes) - anchor is implied

Try it on regex101 (PCRE1)
Try it online! (Python import regex)
Try it online! (Perl 5)
Try it online! (PCRE2 / C++)
Try it online! (PCRE2 / PHP)
Try it online! (Boost / C++)

Regex (ECMAScript / Python), 23🐌, 24🐌, 32, or 33 bytes

(.*([A-Z])(?!.*\2)){26} (23 bytes) 🐌 - Try it online! (ECMAScript) / (Python)
(.*?([A-Z])(?!.*\2)){26} (24 bytes) 🐌 - Try it online! (ECMAScript) / (Python)

ECMAScript lacksand Python lack atomic groups, so they must be emulated using lookahead+capture+backref:

((?=(.*?([A-Z])(?!.*\3)))\2){26} (32 bytes) - Try it online! (ECMAScript) / (Python)
^((?=(.*?([A-Z])(?!.*\3)))\2){26} (33 bytes) - Try it online! (ECMAScript) / (Python)

Regex (Perl 5 / PCRE / Boost / Python 3), 21🐌, 22🐌, 24, or 25 bytes

(?>.*?(\pL)(?!.*\1)){26} (24 bytes) - Try it on regex101 (PCRE1)

Try it online! (Python 3) (24 bytes) - anchor is implied

Try it on regex101 (PCRE1)
Try it online! (Perl 5)
Try it online! (PCRE2 / C++)
Try it online! (PCRE2 / PHP)
Try it online! (Boost / C++)

Regex (ECMAScript), 23🐌, 24🐌, 32, or 33 bytes

(.*([A-Z])(?!.*\2)){26} (23 bytes) 🐌 - Try it online!
(.*?([A-Z])(?!.*\2)){26} (24 bytes) 🐌 - Try it online!

ECMAScript lacks atomic groups, so they must be emulated using lookahead+capture+backref:

((?=(.*?([A-Z])(?!.*\3)))\2){26} (32 bytes) - Try it online!
^((?=(.*?([A-Z])(?!.*\3)))\2){26} (33 bytes) - Try it online!

Regex (Perl 5 / PCRE / Boost / Pythonregex), 21🐌, 22🐌, 24, or 25 bytes

(?>.*?(\pL)(?!.*\1)){26} (24 bytes) 

Try it on regex101 (PCRE1)
Try it online! (Python import regex)

Try it on regex101 (PCRE1)
Try it online! (Python import regex)
Try it online! (Perl 5)
Try it online! (PCRE2 / C++)
Try it online! (PCRE2 / PHP)
Try it online! (Boost / C++)

Regex (ECMAScript / Python), 23🐌, 24🐌, 32, or 33 bytes

(.*([A-Z])(?!.*\2)){26} (23 bytes) 🐌 - Try it online! (ECMAScript) / (Python)
(.*?([A-Z])(?!.*\2)){26} (24 bytes) 🐌 - Try it online! (ECMAScript) / (Python)

ECMAScript and Python lack atomic groups, so they must be emulated using lookahead+capture+backref:

((?=(.*?([A-Z])(?!.*\3)))\2){26} (32 bytes) - Try it online! (ECMAScript) / (Python)
^((?=(.*?([A-Z])(?!.*\3)))\2){26} (33 bytes) - Try it online! (ECMAScript) / (Python)

Edit Java TIO to put its unescaped regex in the Code section - the caveat is that it can't contain */ since it's in a comment (raw string literals aren't available in this version of Java)
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Change the PHP and Ruby TIOs to allow the regex code to be literally anything, thanks to answers to [this question](https://codegolf.stackexchange.com/q/100930/17216)
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Use `<DATA>` to shorten the Perl 5 TIOs
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Demonstrate how the 🐌 versions can work in PCRE2
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
add PCRE2 C++ TIO
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
add Boost version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add the information about `\p{L}` back in
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
oops, forgot to credit @Neil in the answer text.
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
^ anchor is implied in Python 3's regex.match()
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Silly me. Doing this the right way now; thanks to Neil for pointing out my mistake.
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
edited body
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
JavaScript's regex engine is so fast that there can be both positive and negative test cases demonstrated for the slowest version of the regex
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
What was I thinking – the variable-length lookbehind versions can be much shorter.
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Add .NET regex based on the Perl 5 one, to demonstrate that it allows directly quantifying lookarounds
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
continuation of previous edit
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Recognize that there's an even slower -1 byte version
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Show 47 byte JavaScript ES9 answer using the regex
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Demonstrate the slowness of the non-atomic variable-length lookbehind version (in JavaScript, because .NET is a slow regex engine)
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
apply some golfs to the JavaScript and Python TIOs
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Explain in a little bit more detail why the variable-length version can work in Java
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
further explain the lookahead quantification version, and add dividing lines to group the different algorithms
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Directly explain how the lookahead quantification version works, via comments
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading
Apply an optimization to the lookahead quantification versions which I now realize doesn't compromise robustness
Source Link
Deadcode
  • 12.9k
  • 2
  • 71
  • 55
Loading