我需要字符串中正则表达式每次出现的MatchData
.这与Match All Occurrences of a Regex中建议的扫描方法不同,因为这只会给我一个字符串数组(我需要完整的匹配数据,以获取开始和结束信息等).
input = "abc12def34ghijklmno567pqrs"
numbers = /\d+/
numbers.match input # #<MatchData "12"> (only the first match)
input.scan numbers # ["12", "34", "567"] (all matches, but only the strings)
我怀疑我忽略了一些方法.建议?