Skip to content

Instantly share code, notes, and snippets.

@ephesus
Created September 9, 2015 04:29
Show Gist options
  • Save ephesus/8f6ca6e364443cfc7d48 to your computer and use it in GitHub Desktop.
Save ephesus/8f6ca6e364443cfc7d48 to your computer and use it in GitHub Desktop.
implement \1 captures manually in gsub block
#I have no idea what the correct way to do this is
#couldn't use .gsub(regex, 'need \1') because sometimes I needed to format the capture
#so i implmented it in a block to gsub
tex.gsub!(regex) do
res = "thing with \1 and \2 and \3"
Regexp.last_match.captures.each_with_index do |match, i|
if match =~ /^請求項[\p{N},~、-及びおよ]+$/
res = res.gsub(/\\#{i+1}/, format_invention_according_to(match))
else
res = res.gsub(/\\#{i+1}/, match)
end
end
res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment