如何匹配所有出现的正则表达式 [英] How to match all occurrences of a regex

查看:36
本文介绍了如何匹配所有出现的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种快速的方法可以在 Ruby 中找到正则表达式的每个匹配项?我查看了 Ruby STL 中的 Regex 对象并在 Google 上搜索无济于事.

Is there a quick way to find every match of a regular expression in Ruby? I've looked through the Regex object in the Ruby STL and searched on Google to no avail.

推荐答案

使用 scan 应该可以解决问题:

Using scan should do the trick:

string.scan(/regex/)

这篇关于如何匹配所有出现的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆