Bug #1661

RegExp mismatch

Added by Adam Carheden over 2 years ago. Updated 9 months ago.

[ruby-core:23934]
Status:Rejected Start date:06/20/2009
Priority:Normal Due date:
Assignee:Yukihiro Matsumoto % Done:

0%

Category:core
Target version:-
ruby -v:1.8.6, patchlevel 369, i686-linux (Gentoo dev-lang/ruby-1.8.6_p369 ebuild)

Description

#---------------------------
if matches = "all   ".match(Regexp.new("^((all)|(submit)|(view))\s\s*",Regexp::EXTENDED|Regexp::IGNORECASE))
	print "Match\n#{matches.to_a.join("\n\t")}"
else
	print "no match\n"
end
#---------------------------
prints "Match...", but 
#---------------------------
if matches = "all   1".match(Regexp.new("^((all)|(submit)|(view))\s\s*1",Regexp::EXTENDED|Regexp::IGNORECASE))
	print "Match\n#{matches.to_a.join("\n\t")}"
else
	print "no match\n"
end
#---------------------------
prints "no match". Note that the differences is the addition of a '1' to the end of both the regular expression and the string. The same thing happens if I add '\d' instead of 1.


I know I'm using an old version. Possibly it's already fixed. Also, I didn't search for existing bugs because I couldn't figure out how to search by keyword on redmine.ruby-lang.org. Sorry if this is a dup.

History

Updated by Shyouhei Urabe over 2 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto
Parser issue.  Confirmed on all active branches I can test.

\s is eaten by Regexp::EXTENDED.  /\s/x do not have this effect.


zsh % ruby -ve 'p Regexp.new("\s*", Regexp::EXTENDED)'
ruby 1.9.2dev (2009-06-17 trunk 23707) [x86_64-linux]
-e:1:in `initialize': target of repeat operator is not specified: / */x (RegexpError)
        from -e:1:in `new'
        from -e:1:in `<main>'
zsh % ruby -ve 'p /\s*/x'
ruby 1.9.2dev (2009-06-17 trunk 23707) [x86_64-linux]
-e:1: warning: ambiguous first argument; put parentheses or even spaces
/\s*/x

Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Assigned to Rejected
Because "\s" is just one space, and differs from /\s/.

Updated by Nobuyoshi Nakada over 2 years ago

Hi,

At Sat, 20 Jun 2009 10:31:26 +0900,
Hirotsugu Asari wrote in [ruby-core:23942]:
> It seems counterintuitive to me that
> 
> Regexp.new(re,Regexp::EXTENDED).eql?(/#{re}/x)
> 
> can be false for any string 're'.  (In this case, re="\s*")

It's not the point.
"\s*" equals to " *" but not to '\s*' (or "\\s*").

-- 
Nobu Nakada

Also available in: Atom PDF