Try this command (before: none, input: selection or nothing, output:
replace selection):
#!/usr/bin/env ruby
sel = STDIN.read.chomp
sel.match(/^(.+)(.)$/)
left = $~[1]
right = $~[2]
print "\\left#{left}\\right#{right}"
--
Q: Why is this message no more than five sentences?
A: http://five.sentenc.es/