It is to protect the regexp engine from overly expensive computations, as
the repetition can introduce quadratic behavior in the compiler. The Go
engine is concerned about pathological execution - not all engines have
this property (see https://swtch.com/~rsc/regexp/regexp1.html) - and is
being careful.

The 1000 is arbitrary but - speaking just for myself - a repeat count as
high as a thousand tells me that a regular expression is the wrong
mechanism for this problem. A simple loop would be vastly more efficient
(see
https://commandcenter.blogspot.com/2011/08/regular-expressions-in-lexing-and.html).
You are using a steamroller to press a shirt.

-rob


On Sun, Jun 6, 2021 at 4:12 PM M Hasbini <[email protected]> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/f22fb807-7611-4185-bc2b-e7a8f5d8856an%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/f22fb807-7611-4185-bc2b-e7a8f5d8856an%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOXNBZSVTNk7EXPxGNPVwNOCQ1cn7M8hkyHbpV-R3Ve_JxGhPg%40mail.gmail.com.

Reply via email to