Bug #1197
closedregular expression never finishes
Description
=begin
'a foobarfoobar foobarfoobar"'.scan(/^(([^"\n]*|"([^"]|"")+")+)($)/m)
I tried with Debian-testing, Gentoo-stable Ruby1.8 and Debian-testing Ruby1.9, the results are same: the command never finishes, CPU usage 100%.
Is this a bad regular expression? If it is, how can I know?
I am neither a master nor a fan of PHP, I just tried it before filing a bug because of curiosity:
which exits normally. Not in Ruby, with or without the multiline.
=end
Files
Updated by shyouhei (Shyouhei Urabe) about 15 years ago
- Status changed from Open to Rejected
=begin
Exits normally? On my machine that "echo $a[0];" just prints nothing.
PHP gives up running that script, while ruby tries it anyway.
As you guessed this is a bad regex that backtracks over and over again.
The only way I can think of for you to know which is bad, is to learn
how it works.
=end
Updated by naruse (Yui NARUSE) about 15 years ago
=begin
Use 'a foobarfoobar foobarfoobar"'.scan(/^([^"\n](?:"[^"](?:""[^"])")*)$/m)
=end