Okay; since 90% of what we need is present, why not add a new method to Regexp, #gmatch(str, pos = nil, flags = nil). Adding pos to #match seems a poor fit because of the flags argument already present. Also, if a MatchData is passed as str, it should implicitly call MatchData#end for pos unless pos is non-nil. IMO, being explicit about doing a //g-type match is a Good Thing.
Thoughts?
-a
···
–
austin ziegler
Sent from my Treo
Hi,
Okay; since 90% of what we need is present, why not add a new
method to Regexp, #gmatch(str, pos = nil, flags = nil).
Adding pos to #match seems a poor fit because of the flags
argument already present.
Regexp#match in present takes only str.
Also, if a MatchData is passed as str, it should implicitly
call MatchData#end for pos unless pos is non-nil. IMO, being
explicit about doing a //g-type match is a Good Thing.
MatchData as String? Well, in such case I’d expect matching
to $& (equals $~.to_s).
···
At Sat, 14 Dec 2002 11:53:20 +0900, Austin Ziegler wrote:
–
Nobu Nakada
Hi,
Okay; since 90% of what we need is present, why not add a new
method to Regexp, #gmatch(str, pos = nil, flags = nil). Adding
pos to #match seems a poor fit because of the flags argument
already present.
Regexp#match in present takes only str.
Sorry, I was confusing #match and ::new (: You’re right. #gmatch
isn’t necessary.
Also, if a MatchData is passed as str, it should implicitly
call MatchData#end for pos unless pos is non-nil. IMO, being
explicit about doing a //g-type match is a Good Thing.
MatchData as String? Well, in such case I’d expect matching
to $&(equals $~.to_s).
Actually, I was thinking something like:
def gmatch(str, pos = nil)
if str.class == MatchData
if pos.nil?
match(str.string, str.end(0))
else
match(str.string, pos)
end
else
match(str, pos)
end
end
I understand that checking the class is considered a bad thing, so
this should be viewed as a model, only.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.14 at 00.19.50
···
On Sat, 14 Dec 2002 12:45:21 +0900, nobu.nokada@softhome.net wrote:
At Sat, 14 Dec 2002 11:53:20 +0900, > Austin Ziegler wrote:
Hi,
Also, if a MatchData is passed as str, it should implicitly
call MatchData#end for pos unless pos is non-nil. IMO, being
explicit about doing a //g-type match is a Good Thing.
MatchData as String? Well, in such case I’d expect matching
to $&(equals $~.to_s).
Actually, I was thinking something like:
def gmatch(str, pos = nil)
if str.class == MatchData
if pos.nil?
match(str.string, str.end(0))
else
match(str.string, pos)
end
else
match(str, pos)
end
end
I understand that checking the class is considered a bad thing, so
this should be viewed as a model, only.
I worry if the behavior may surprise/confuse users.
I got new idea, a new method like this.
class MatchData
def next_match(re)
re.match(self.string, self.end(0))
end
end
md = /\A/.match(foostr)
while md = md.next_match(/\Gfoo/)
puts md.to_s
end
But MatchData#sring returns frozen copy, and the name never
look good. Rather, StringScanner will be better.
···
At Sat, 14 Dec 2002 14:27:22 +0900, Austin Ziegler wrote:
–
Nobu Nakada