title: Escaping sed strings correctly
body: <p>I have a regex and replacement pattern that have both been tested in Notepad++ on my input data and work correctly.  When I put them into a sed expression, however, nothing gets matched.</p>
  
  <p>Here is the sed command:</p>
  
  <pre><code> # SEARCH = ([a-zA-Z0-9.]+) [0-9] (.*)
   # REPLACE = \2 (\1)
  
   sed -e 's/\([a-zA-Z0-9.]+\) [0-9] \(.*\)/\2 \(\1\)/g'
  </code></pre>
  
  <p>Here is a sampling of the data:</p>
  
  <pre><code>jdoe 1 Doe, John
  jad 1 Doe, Jane
  smith 2 Smith, Jon
  </code></pre>
  
  <p>and the desired output:</p>
  
  <pre><code>Doe, John  (jdoe)
  Doe, Jane  (jad)
  Smith, Jon (smith)
  </code></pre>
  
  <p>I have tried removing and adding escapes to different characters in the sed expression, but either get nothing matched or something along the lines of:</p>
  
  <pre><code>sed: -e expression #1, char 42: invalid reference \2 on `s' command's RHS
  </code></pre>
  
  <p>How can I get this escaped correctly?</p>