忽略正则表达式中用于重复模式的捕获组

Ignoring capture group in Regex that is used for repeating the patten

/((\w))/ 查找重复字母。我希望避免通过忽略与第二个捕获组匹配的字母而生成的二维数组,如下所示:/((?:\w))/。这似乎是不可能的。有什么想法吗?

Rubular example

如果你是说你正在使用 String#scan, you can post-process the result to return only the first items Enumerable#map:

'helloo'.scan(/((\w))/)
# => [["ll", "l"], ["oo", "o"]]

'helloo'.scan(/((\w))/).map { |m| m[0] }
# => ["ll", "oo"]

您不需要任何 捕获组:

str = [*'a+'..'z+', *'A+'..'Z+', *'0+'..'9+', '_+'].join('|')
  #=> "a+|b+| ... |z+|A+|B+| ... |Z+|0+|1+| ... |9+|_+" 

"aaabbcddd".scan(/#{str}/)
  #=> ["aaa", "bb", "c", "ddd"]

但如果你坚持要一个:

"aaabbcddd".scan(/(#{str})/).flatten(1)
  #=> ["aaa", "bb", "c", "ddd"]

这是作弊吗?你确实问过它是否可能