From: Brian Candler Date: 2009-01-07T22:03:35+09:00 Subject: Re: A question about running external program Justin Collins wrote: > irb(main):003:0> puts `uname -r | sed > 's/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\\1/' && ps x | grep uname` I think that's not quite right, because \\1 is still converted into a single character with ASCII code 1, rather than being passed to sed as \1 irb(main):013:0> `echo 's/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\\1/'` => "s/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\001/\n" So as far as I can see, you need to use \\\\1 to get a literal \ followed by 1 irb(main):014:0> `echo 's/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\\\\1/'` => "s/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\\1/\n" Escapes like \. and \( are OK, but for consistency you can escape them all in the same way: irb(main):015:0> `echo 's/\\\\([^\\\\.]*\\\\.[^\\\\.]*\\\\)\\\\.*.*/\\\\1/'` => "s/\\([^\\.]*\\.[^\\.]*\\)\\.*.*/\\1/\n" -- Posted via http://www.ruby-forum.com/.