Regex with named capture groups getting all matches in Ruby

前端 未结 10 1957
滥情空心
滥情空心 2021-02-02 08:12

I have a string:

s=\"123--abc,123--abc,123--abc\"

I tried using Ruby 1.9\'s new feature \"named groups\" to fetch all named group info:

10条回答
  •  孤独总比滥情好
    2021-02-02 08:54

    Chiming in super-late, but here's a simple way of replicating String#scan but getting the matchdata instead:

    matches = []
    foo.scan(regex){ matches << $~ }
    

    matches now contains the MatchData objects that correspond to scanning the string.

提交回复
热议问题