g | x | w | all
Bytes Lang Time Link
036Haskell + hgl240428T162746Zcorvus_1
094Python + numpy240426T115722Zcorvus_1
195Python240426T094052ZDLosc
060Charcoal240426T152345ZNeil
120Java 10240426T104459ZKevin Cr
313005AB1E240426T103723ZKevin Cr
046Python + Regenerate240426T063539ZDLosc
030Perl 5 + M5.10.0 a240426T080030ZDom Hast
072JavaScript Node.js240426T022016Zl4m2
214Python240426T061359ZBubbler

Haskell + hgl, 43, 40 36 bytes

-3 bytes thanks to Wheat Wizard
-6 bytes

Requires -XExtendedDefaultRules

import P
s=wn(eF 1>~rM β)<ø<<gcx

Attempt This Online!

Ungolfed:

β = ['a'..'z']
ø = null
allStrings = [1..] >>= (`replicateM` β)
s = filterNot allStrings . ø << allCompleteRegexMatches

Python + numpy, 94 bytes

def f(s,i=0):re.sub(s,"",t:=numpy.base_repr(i,36).lower())or print(t);f(s,i+1)
import re,numpy

Attempt This Online!

Uses the iterate-all-strings technique from @l4m2's answer

Python, 214 211 198 195 bytes

-3 bytes thanks to emanresu A

def f(r,n=0):
 def m(r,i=-2):t,*R=r;p=lambda x,y:[a+b for a in x for b in y];return(t>3)*R or t>1and[p,list.__add__][t%2](*map(m,R))or(i<n*t)*R and[""]+p(m(R),m(r,i+1))
 *map(print,m(r)),f(r,n+1)

Attempt This Online!

Call f with a regex AST argument, get infinite matches printed to stdout. The AST is structured as follows (adapted from Bubbler's answer):

a     -> [4, 'a']
(A|B) -> [3, A, B]
AB    -> [2, A, B]
ABC   -> [2, A, [2, B, C]]
(A)*  -> [1] + A
(A)?  -> [0] + A

where [1] + A means "concatenate a 1 to the front of list A."

I've been golfing this for... a while... and it's way too late. So the detailed explanation will have to wait. The basic idea, though, is that we let n be the max repetitions for the * operator and recurse the function infinitely with increasing values of n. There's a lot of redundant output, but the correct outputs are all there.

Charcoal, 60 bytes

≔↨N²θ⊞υAW∧υ⊟υ≡§ι⁰ωF⮌Φιλ⊞υκ?F∧θ⊟θ⊞υ§ι¹*W∧θ⊟θ⊞υ§ι¹|⊞υ§ι∨∧θ⊟θ²ι

Try it online! Link is to verbose version of code. Takes as input the 0-indexed match and the regex as an AST (see below). Explanation: Port of @Bubbler's Python answer.

≔↨N²θ

Input n and convert it to binary.

⊞υA

Start by processing the whole regex.

W∧υ⊟υ

Repeat until there are no more terms to process.

≡§ι⁰

Switch over the first element of the term.

ωF⮌Φιλ⊞υκ

If this is a concatenation then push all of the child terms (in reverse order, since they'll be processed by popping).

?F∧θ⊟θ⊞υ§ι¹

If this is an option then push the child term only if the next bit is a 1.

*W∧θ⊟θ⊞υ§ι¹

If this is an option then repeatedly push the child term while the next bit is a 1.

|⊞υ§ι∨∧θ⊟θ²

If this is an alternation then push one of the two child terms depending on the value of the next bit.

ι

Otherwise just print the term.

Terms have the following form:

('', terms...) Concatenation
('?', term) Option
('*', term) Repetition
('|', term, term) Alternation

Note that as an optimisation if all of the terms are letters then you can use the string formed by concatenating them together e.g. '?a' is equivalent to ('?', 'a') while ('', 'a', 'b') is equivalent to ab.

Anything that does not match the above is treated as a literal.

63 bytes to output the first n matches (plus a leading blank line):

FEN↨鲫⸿⊞υηW∧υ⊟υ≡§κ⁰ωF⮌Φκμ⊞υλ?F∧ι⊟ι⊞υ§κ¹*W∧ι⊟ι⊞υ§κ¹|⊞υ§κ∨∧ι⊟ι²κ

Try it online! Link is to verbose version of code. Takes as input the number of matches and the regex as an AST as above.

Java 10, 120 bytes

r->{var i=java.math.BigInteger.ONE;for(var t="";;i=i.add(i.ONE),t=i.toString(36))if(t.matches(r))System.out.println(t);}

Port of @l4m2's JavaScript answer, so make sure to upvote that answer as well.

Try it online.

Explanation:

r->{                              // Method with String parameter and no return-type
  var i=java.math.BigInteger.ONE; //  Loop-BigInteger `i`, starting at 1
  for(var t="";                   //  Temp-String `t`, starting empty
                                  //  Loop indefinitely:
      ;                           //    After every iteration:
       i=i.add(i.ONE),            //     Increase `i` by 1
       t=i.toString(36))          //     Change `t` to `i` as base-36 string
    if(t.matches(r))              //   If `t` fully† matches the input-regex:
      System.out.println(t);}     //    Print `t` with trailing newline

† Java's String#matches implicitly adds a leading ^ and trailing $ to match the regex on the entire String.

05AB1E, 31 (or 30?) bytes

áÞæJÙʒ’St•–.•«?("ÿ",~r/^ÿ$/)’.E

Outputs an infinite list.

Try it online.

Could be -1 byte if we're allowed to output duplicated results, by removing the Ù:

Try it online.

Explanation:

05AB1E lacks regexes, but we can use .E to execute a string as Elixir code. So this uses Elixir's String.match.

á          # Only leave the letters of the (implicit) input-regex
 Þ         # Convert it to an infinite cycled list
  æ        # Pop and get the powerset of this
   J       # Join each inner list of characters to a string
    Ù      # (optionally) Uniquify these stringsʒ’St•–.•«?("ÿ",~r/^ÿ$/)’.E
     ʒ     # Filter this infinite list of strings by:
      ’St•–.•«?("ÿ",~r/^ÿ$/)’
           #  Push dictionary string 'String.match("ÿ",~r/^ÿ$/)', where the first `ÿ`
           #  is replaced with the current string and the second with the (implicit)
           #  input-regex
        .E #  Pop and evaluate it as Elixir code, resulting in true/false
           # (after which the filtered infinite list is output implicitly as result)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ’St•–.•«?("ÿ",~r/^ÿ$/)’ is String.match("ÿ",~r/^ÿ$/).

Python + Regenerate, 49 46 bytes

-3 bytes thanks to xnor

from regenerate import*
main(input(),[],1e999)

Takes the regex from stdin and outputs all matches to stdout.

Try it online!

Regenerate is a language that does exactly this (and more). The Python code takes a line of input and calls Regenerate's main function with that regex, an empty list of program inputs, and a repetition limit of infinity.

Perl 5 + -M5.10.0 -a, 30 bytes

}{/^@F$/&&say;$_++;y/1/a/;redo

Try it online!

JavaScript (Node.js), 72 bytes

s=>{for(i=9n,t='';;t=i.toString(36))t.replace(s,i)==i++&&console.log(t)}

Try it online!

Python, 214 bytes

lambda r,i:g(r,i)[0]
def g(r,i,s=''):
 try:
  c,k=r;j=i//2
  if c>2:R=g(k[i%2],j)
  elif c>1:
   for r in k:S,i=g(r,i);s+=S
   R=s,i
  else:
   while i%2:S,i=g(k,j);s+=S;j=i//2;i*=c
   R=s,j
 except:R=r,i
 return R

Attempt This Online!

I guess we need at least one answer that solves the problem from scratch, so here is one. The regex is input as an AST in the following form:

(A|B) -> (ALT, [A, B])
ABC.. -> (SEQ, [A, B, C, ..])
(A)*  -> (STAR, A)
(A)?  -> (OPT, A)
a     -> 'a'

where ALT, SEQ, STAR, and OPT are integer constants.

The lambda at the top takes a regex and a 0-based index, and outputs a generated string.

The index i is treated as a stream of bits (which ends with infinitely many zeros), and all decisions are made in binary fashion:

This solves the challenge because every finite matching string has a path that generates it, which can be encoded in a finite number of bits. It is explicitly allowed to output the same string multiple times, and this solution actually outputs the same string infinitely many times (since the bits other than the part used to encode the output can be anything).

The way of passing around the remaining bits of i is similar to passing remaining buffer in recursive descent parsing.