Skip to main content
demonstrate PCRE's compatibility with Ruby's subroutine call syntax
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

Regex (PCRE / Ruby), 12 bytes

Try it online!Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Ruby

Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - JavaTry it online! - Java

Regex (Ruby), 12 bytes

Try it online!

Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Java

Regex (PCRE / Ruby), 12 bytes

Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Ruby

Try it online! - Perl
Try it online! - PCRE1
Try it online! - PCRE2
Try it online! - Java

improve the explanation of the Java regex
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
^           # Assert we're at the beginning of the string.
(
    a       # Match one more 'a' per each iteration of this loop.
    # Lookahead assertion - when this finishes, the regex engine's "cursor"
    # "cursor" will jump back to the same position as it was in when it entered the
    # lookahead here. It's atomic, so the regex engine can't backtrack into
    # the lookahead once it enteredhas completed its match or non-match. This means
    # the main loop will exit immediately if this lookahead herefails to match
    # (due to running out of 'b' characters to match), or if the 'a' above
    # fails to match.
    (?=
        a*      # Skip over as many 'a' as necessary to get to the first 'b'.
        # Capture \2, embedding within it the previous contents of itself.
        # If this is the first iteration, \2 will be unset, so capture a
        # single 'b' in \2. Otherwise, append one more 'b' to the previous
        # contents of \2.
        (
            \2?+    # Optionally match \2, but if it does match, lock that
                    # match in (don't backtrack to here and try not making the
                    # match, in the case that a non-match occurs after this
                    # point). This is guaranteed to fail to match if and only if
                    # we're on the first iteration, due to \2 being unset. On
                    # subsequent iterations, since \2 will have been captured
                    # starting at the first non-'a' character, and always starts
                    # its attempted match there, it will be guaranteed to match.
            b       # Match one 'b'.
        )
    )
)+
\2          # Match however many 'b' we captured in \2.
$           # Assert we're at the end of the string.
^           # Assert we're at the beginning of the string.
(
    a       # Match one more 'a' per each iteration of this loop.
    # Lookahead assertion - when this finishes, the regex engine's
    # "cursor" will jump back to the same position as it was in when
    # it entered the lookahead here.
    (?=
        a*      # Skip over as many 'a' as necessary to get to the first 'b'.
        # Capture \2, embedding within it the previous contents of itself.
        # If this is the first iteration, \2 will be unset, so capture a
        # single 'b' in \2. Otherwise, append one more 'b' to the previous
        # contents of \2.
        (
            \2?+    # Optionally match \2, but if it does match, lock that
                    # match in (don't backtrack to here and try not making the
                    # match, in the case that a non-match occurs after this
                    # point). This is guaranteed to fail to match if and only if
                    # we're on the first iteration, due to \2 being unset. On
                    # subsequent iterations, since \2 will have been captured
                    # starting at the first non-'a' character, and always starts
                    # its attempted match there, it will be guaranteed to match.
            b       # Match one 'b'.
        )
    )
)+
\2          # Match however many 'b' we captured in \2.
$           # Assert we're at the end of the string.
^           # Assert we're at the beginning of the string.
(
    a       # Match one more 'a' per each iteration of this loop.
    # Lookahead assertion - when this finishes, the regex engine's "cursor"
    # will jump back to the same position as it was in when it entered the
    # lookahead here. It's atomic, so the regex engine can't backtrack into
    # the lookahead once it has completed its match or non-match. This means
    # the main loop will exit immediately if this lookahead fails to match
    # (due to running out of 'b' characters to match), or if the 'a' above
    # fails to match.
    (?=
        a*      # Skip over as many 'a' as necessary to get to the first 'b'.
        # Capture \2, embedding within it the previous contents of itself.
        # If this is the first iteration, \2 will be unset, so capture a
        # single 'b' in \2. Otherwise, append one more 'b' to the previous
        # contents of \2.
        (
            \2?+    # Optionally match \2, but if it does match, lock that
                    # match in (don't backtrack to here and try not making the
                    # match, in the case that a non-match occurs after this
                    # point). This is guaranteed to fail to match if and only if
                    # we're on the first iteration, due to \2 being unset. On
                    # subsequent iterations, since \2 will have been captured
                    # starting at the first non-'a' character, and always starts
                    # its attempted match there, it will be guaranteed to match.
            b       # Match one 'b'.
        )
    )
)+
\2          # Match however many 'b' we captured in \2.
$           # Assert we're at the end of the string.
added 7 characters in body; deleted 15 characters in body
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52

The purpose of this post is to demonstrate and explain the full list of golfed pure regexes that solve this challenge, and the range of compatibility of each among seven different regex engines, and rank them by length, all together in one post. Others' answers used the best regexes before this post; I am including them for completenessthey are listed below. I ported the Java one to three other sets of regex engines, including Python 3's regex library.

The purpose of this post is to demonstrate and explain the full list of golfed pure regexes that solve this challenge, and the range of compatibility of each among seven different regex engines, and rank them by length, all together in one post. Others' answers used the best regexes this post; I am including them for completeness. I ported the Java one to three other sets of regex engines, including Python 3's regex library.

The purpose of this post is to demonstrate and explain the full list of golfed pure regexes that solve this challenge, and the range of compatibility of each among seven different regex engines, and rank them by length, all together in one post. Others' answers used the best regexes before this post; they are listed below. I ported the Java one to three other sets of regex engines, including Python 3's regex library.

added 12 characters in body; deleted 7 characters in body; deleted 3 characters in body; added 9 characters in body
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Explain the .NET regex in my own words, since my post is getting more upvotes than I expected.
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Explain the non-recursive regex in my own words, since my post is getting more upvotes than I expected.
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Explain the recursive regex, since my post is getting more upvotes than I expected.
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
the 29 byte version shouldn't have "Python with 'regex' import" in a large font in its language name, because the 11 byte version works in that engine
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
put the links to the answers using the 11 byte regex in proper chronological order of when they adopted it; add a .NET regex answer link(?'-
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
deleted 93 characters in body
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading
Source Link
Deadcode
  • 11.9k
  • 1
  • 66
  • 52
Loading