STRING METHODS
Up to now, we’ve used methods of the Regexp class when processing strings. In fact, pattern matching can go both ways due to the fact that the String class has a few regular expression methods of its own. These include =~ and match (so you can switch the order of the String and Regexp objects when matching), plus the scan method which iterates through a string looking for as many matches as possible. Each match is added to an array. Here, for example, I am looking for matches on the letters ‘a’, ‘b’ or ‘c’. The match method returns the first match (‘a’) wrapped up in a MatchData object; but the scan method keeps scanning along the string and returns all the matches it finds as elements in an array: