I want to search through a block of text and build an array of all
strings contained within this text that match a given pattern. I know
the following hack will work, but it seems like a misuse of the gsub
method:
Assume that ‘text’ contains the block of text and that ‘pat’
is a Regexp instance containing the pattern to match.
matchingStrings = []
text.gsub(pat) {
|m|
matchingStrings << m
}
What if we wanted to expand it a little? For instance, Iets say the
person has a typo like phat instead of pat. Is there a good method for
searching and returning CLOSEST matches but not exact?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.