Using named capture groups inside Ruby gsub blocks (regex) Using named capture groups inside Ruby gsub blocks (regex) ruby ruby

Using named capture groups inside Ruby gsub blocks (regex)


You are looking for

"foo /(bar)".gsub(/(?<my_word> \(.*?\) )/x) do |match|  puts "$1 = #{$1} and $my_word = #{$~[:my_word]}"end