PHIL Sawyer
asked on
Finding all occurrences
Hello
I found this really interesting example on reg expressions
eg
def show_regexp(string, pattern)
match = pattern.match(string)
if match
"#{match.pre_match}->#{mat ch[0]}<-#{ match.post _match}"
else
"no match"
end
end
We could use this method like this:
show_regexp('very interesting', /t/) # => very in->t<-eresting
How could I modify this so I can see all occurrences - i.e.
show_regexp('very interesting', /t/) # => very in->t<-eres->t<-ing
Regards
I found this really interesting example on reg expressions
eg
def show_regexp(string, pattern)
match = pattern.match(string)
if match
"#{match.pre_match}->#{mat
else
"no match"
end
end
We could use this method like this:
show_regexp('very interesting', /t/) # => very in->t<-eresting
How could I modify this so I can see all occurrences - i.e.
show_regexp('very interesting', /t/) # => very in->t<-eres->t<-ing
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very helpful
Thanks