Ruby 如何让正则 match 获取全部匹配的东西

string2020 · April 28, 2015 · Last by yesmeck replied at April 28, 2015 · 2366 hits

我想匹配:汉字,字母,数字 也就是取出字符串中所有的汉字,字母,数字

def format_name(name)
  res = name.match(/[\p{Han}|a-zA-Z0-9]+/)
  puts res
end

format_name('*&^&%我是bo.-*/dy123')

输出是:我是 bo 第一次匹配之后,没有继续匹配了,如何取得所有的匹配

String#scan

You need to Sign in before reply, if you don't have an account, please Sign up first.