title: docx unbreakable words
body: <p>I'm trying to replace words in a docx file like described <a href="http://msdn.microsoft.com/en-us/library/office/bb508261.aspx" rel="nofollow">here</a>:</p>
  
  <pre><code>public static void SearchAndReplace(string document)
  {
      using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
      {
          string docText = null;
          using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
          {
              docText = sr.ReadToEnd();
          }
  
          Regex regexText = new Regex("Hello world!");
          docText = regexText.Replace(docText, "Hi Everyone!");
  
          using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
          {
              sw.Write(docText);
          }
      }
  }
  </code></pre>
  
  <p>That's working fine except that sometimes for SomeTest in a document you would get something like:</p>
  
  <pre><code>    &lt;w:t&gt;
          Some
      &lt;/w:t&gt;
  &lt;/w:r&gt;
  
  &lt;w:r w:rsidR="009E5AFA"&gt;
      &lt;w:rPr&gt;
          &lt;w:b/&gt;
          &lt;w:color w:val="365F91"/&gt;
          &lt;w:sz w:val="22"/&gt;
      &lt;/w:rPr&gt;
      &lt;w:t&gt;
          Test
      &lt;/w:t&gt;
  &lt;/w:r&gt;
  </code></pre>
  
  <p>And of course replacement fails. Perhaps there is a workaround to make some words unbreakable in docx? Or perhaps I'm doing replace wrong?</p>