I have a simple Ruby regex that is taking very long to compute:
"fußball "*20 =~ /^([\S\s]{1000})/i
If I remove /i
flag it works very fast. Why is it running so slowly? (I didn't wait for execution to finish)
I know this regex might not make sense, but I'm wondering what is under the hood.
Bug report: https://bugs.ruby-lang.org/issues/14418
By default .
doesn't match newlines. [\s\S]
is a hack around that problem. In Ruby you can use the /m flag to make the dot match all characters. It's in the documentation Ruby Metacharacters and Escapes
[\S\s]
for an unknown reason is very slow but you can change it to "fußball "*20 =~ /^(.{1000})/mi
that does the same but faster
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With