title: Using regex to select hide matching words - MS Word
body: <p>I am trying to create a macro for ms word, for finding all matching words using regex and setting them as hidden. I am able to run the macro without errors, but without any result. When I use some word instead of regex, the macro works. Is the regex wrong for VBA or macro is incorrect? I am lost, could you please help?</p>
  
  <p>Macro:</p>
  
  <pre><code>Sub HideElements()
    Dim oRng As Word.Range
    Set oRng = ActiveDocument.Range
  
    With oRng.Find
      .Text = "(?'Name'.*?),.*?\| Pnumber:(?'Pnumber'.*?)\| INumber:(?'Inumber'\d+)\|?.*?$\n(?'Addr'.*?.?)\|.*?$"
      .Replacement.Font.Hidden = True
      .MatchWildcards = True
      .Execute Replace:=wdReplaceAll
    End With
  </code></pre>
  
  <p>Sample text:</p>
  
  <blockquote>
    <p>John Serato, Active | Pnumber: A99999-CC | INumber:9139229719 | AAV
    Certified 
        New York, NY, USA | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididun</p>
  </blockquote>