Project

General

Profile

Actions

Bug #1197

closed

regular expression never finishes

Added by Mage (Péter Szabó) about 15 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux]
[ruby-core:22361]

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

regexp.rb (142 Bytes) regexp.rb Mage (Péter Szabó), 02/23/2009 10:01 PM
Actions #1

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

Actions #2

Updated by naruse (Yui NARUSE) about 15 years ago

=begin
Use 'a foobarfoobar foobarfoobar"'.scan(/^([^"\n](?:"[^"](?:""[^"])")*)$/m)
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0