title: Regex to find a pattern, then insert into the pattern
body: <p>Using Excel VBA</p>
  
  <p>I'm not sure if you can do this with regex but what i'm trying to do is for a sting like</p>
  
  <p>"ThisIsAn ExampleString"</p>
  
  <p>Find each instance of a lowercase letter followed immediately by an uppercase letter, and then insert a pipe into it.</p>
  
  <p>So the final result would be like</p>
  
  <p>"This|Is|An Example|String"</p>
  
  <p>So I'm guessing the pattern is "[a-z][A-Z]"</p>
  
  <p>I'm starting to think i'm barking up the wrong tree with regex and should just try some sort of function.</p>
  
  <p>Edit:</p>
  
  <p>Thanks to all who gave answers below, you have given me the solution.</p>
  
  <p>For anyone else reading this, this is what I ended up with:</p>
  
  <pre><code>Sub PipeInsert()
  
      Dim cell As Range
      For Each cell In Selection
          cell.Value = ReplaceTest(cell.Value, "([a-z])([A-Z])", "$1|$2")
      Next
  
  End Sub
  
  
  Function ReplaceTest(str1, patrn, replStr)
      Dim regEx
  
      ' Create regular expression.
      Set regEx = New RegExp
      regEx.Pattern = patrn
      regEx.Global = True
  
      ' Make replacement.
      ReplaceTest = regEx.Replace(str1, replStr)
  End Function
  </code></pre>