title: Sed replace hyphen with underscore
body: <p>new to regex and have a problem. I want to replace hyphens with underscores in certain places in a file. To simplify things, let's say I want to replace the <em>first</em> hyphen. Here's an example "file":</p>
  
  <pre><code>dont-touch-these-hyphens
  leaf replace-these-hyphens
  </code></pre>
  
  <p>I want to replace hyphens in all lines found by</p>
  
  <pre><code>grep -P "leaf \w+-" file
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>sed -i 's/leaf \(\w+\)-/leaf \1_/g' file
  </code></pre>
  
  <p>but nothing happens (wrong replacement would have been better than nothing). I've tried a few tweaks but still nothing. Again, I'm new to this so I figure the above "should basically work". What's wrong with it, and how do I get what I want? Thanks.</p>