Bug #1661
closedRegExp mismatch
Description
=begin
#---------------------------
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.
=end
Updated by shyouhei (Shyouhei Urabe) about 16 years ago
- Category set to core
- Status changed from Open to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
=begin
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 `'
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
=end
Updated by nobu (Nobuyoshi Nakada) about 16 years ago
- Status changed from Assigned to Rejected
=begin
Because "\s" is just one space, and differs from /\s/.
=end
Updated by nobu (Nobuyoshi Nakada) almost 16 years ago
=begin
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
=end