Project

General

Profile

Actions

Bug #9728

closed

Regexp bug

Added by sawa (Tsuyoshi Sawada) almost 10 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
Ruby 2.0
[ruby-core:61959]

Description

As reported in StackOverflow (http://stackoverflow.com/questions/23004527) (with a wrong expectation), the following regex pattern with the * operator does not match.

"ab" =~ /(?!^a).*b/
# => nil

When ? is used instead, it seems to match correctly:

"ab" =~ /(?!^a).?b/
# => 1

According to the original reporter of the linked site, this does not happen in Ruby 1.9.3.

Updated by phasis68 (Heesob Park) almost 10 years ago

I found this issue is related with the ONIG_DONT_OPTIMIZE macro.

If I insert "#define ONIG_DONT_OPTIMIZE" in regint.h, the regexp works like Ruby 1.9.3.

before define:

C:\work\ruby-2.2.0-r45349>miniruby -ve 'p "ab"=~/(?!^a).*b/;'
ruby 2.2.0dev (2014-03-16 trunk 45349) [x64-mswin64_120]
nil

after define:

C:\work\ruby-2.2.0-r45349>miniruby -ve 'p "ab"=~/(?!^a).*b/;'
ruby 2.2.0dev (2014-03-16 trunk 45349) [x64-mswin64_120]
1

Updated by k_takata (Ken Takata) over 9 years ago

This bug is fixed with the following Onigmo's commit:
https://github.com/k-takata/Onigmo/commit/15ddec6d18e27fdc1988236764e766fd5892ecf5
This fix is included in Onigmo 5.15.0.

Updated by k_takata (Ken Takata) over 9 years ago

  • Status changed from Open to Closed

Fixed with r47598.

Updated by usa (Usaku NAKAMURA) over 9 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE

partially backport r47598 into ruby_2_1 branch at r47954.

Updated by usa (Usaku NAKAMURA) over 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE

Backported into ruby_2_0_0 at r47976.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0