Project

General

Profile

Actions

Bug #8565

closed

Compiled Regexp comparation bug

Added by pyromaniac (Arkadiy Zabazhanov) over 11 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]
Backport:
[ruby-core:55627]

Description

2.0.0p195 :001 > Regexp.new('/') == ///
=> false

There is no such problem in latest 1.9.3, expression return true

Updated by Anonymous over 11 years ago

I took a quick look at why this is happening. The equality fails because the source of the two regexps is different:

1.9.3:

Regexp.new('/').source
=> "\/"
///.source
=> "\/"

2.0.0:

Regexp.new('/').source
=> "\/"
///.source
=> "/"

Updated by cedric.brancourt (Cedric Brancourt) over 11 years ago

Hopefully this is not a bug (or I think it is not).

When you create new regexp with :
%r"/" and Regexp.new("/") your quote are the delimiters

when you create regexp with slashes /// the slashes (/) are your delimiters. Your regexp should end at the second / but fortunately you can escape this one with a backslash.
So your backslash is there used to escape the second one. This mean that your regexp /// is equal to %r"/"

[6] pry(main)> /// == %r"/"
=> true

See http://www.ruby-doc.org/core-2.0/Regexp.html#label-Metacharacters+and+Escapes

Actions #3

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Open to Closed
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0