Ruby global match regexp?

后端 未结 3 1263
终归单人心
终归单人心 2020-12-08 03:42

In other languages, in RegExp you can use /.../g for a global match.

However, in Ruby:

\"hello hello\".match /(hello)/

3条回答
  •  无人及你
    2020-12-08 04:42

    use String#scan. It will return an array of each match, or you can pass a block and it will be called with each match.

    All the details at http://ruby-doc.org/core/classes/String.html#M000812

提交回复
热议问题