Why one regex behaves differently for scan and match methods?
str = "A man, a plan, a canal -- Panama"
/\w+/.match(str).to_s #=> #<MatchData "A"> i.e. just "A"
str.scan(/\w+/) #=> ["A", "man", "a", "plan", "a", "canal", "Panama"]
The methods should bring the same result, shouldn’t they?
matchwill only returns the first match, because that’s what it does, whilescanwill return all matches. The regexes used do actually work exactly the same. See this.