The reason is that the only way to implement repetition in an NFA or DFA is literally to repeat the expression, so asking for `a{6}` means to generate the machine for `aaaaaa`. It is a notational convenience only, a macro mechanism if you will. Other "regexp" packages, which do not adhere to the clear, theoretically strong properties of regular languages, are free to use other techniques, at the cost of potentially catastrophic execution times.
-rob On Sun, Jun 6, 2021 at 6:18 PM Alberto Donizetti <alb.donize...@gmail.com> wrote: > Probably not a bug, since it's documented: > > https://golang.org/pkg/regexp/syntax/ > > > Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n} > reject forms that create a minimum > > or maximum repetition count above 1000. Unlimited repetitions are not > subject to this restriction. > > I don't know the reason for such restriction. If I had to guess, I'd say > that's because the DFA approach > Go uses for regexp requires counting repetitions to be expanded into > states (they're not implemented > using a loop), so some kind of limit is needed to ensure the resulting > automata is not too big. > > Alberto > On Sunday, 6 June 2021 at 08:12:41 UTC+2 M Hasbini wrote: > >> Playground: https://play.golang.org/p/opVpDD5Ts8S >> >> Here's an example regex that fails to compile: `[a-zA-Z0-9]{1001,}` >> >> Here's where the 1000 is specified: >> https://github.com/golang/go/blob/4d9ecde/src/regexp/syntax/parse.go#L250 >> >> Other languages regex engine behavior: The regex is valid on all >> languages in https://regex101.com/r/JzGrYG/1 except Go. >> >> Is there a reason for this limit or is this a bug? >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/533c44b4-6e3b-4d8e-a27a-57993e76665bn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/533c44b4-6e3b-4d8e-a27a-57993e76665bn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOXNBZTsBsiyP0FRCVeXZNLE2eUYFwRofRsY9SZxbeJnt4iuqA%40mail.gmail.com.