title: Regular expressions - Reference the first match in a search
body: <p>I don't quite know how to describe my problem in a short title so I am sorry if the title for this question is a bit mis-leading.
  But I really don't know what the thing I am looking for is called or if it is even possible.</p>
  
  <p>I am trying to use a regular expression to find everything between a set of matching tags in HTML.
  This was easy for me when I was testing with static tags because I could just search for everything in between two pieces of text such as <code>\{myTag\}(someExpression)\{\/myTag\}</code></p>
  
  <p>My problem comes with the fact that 'myTag' could be anything.
  I just don't know how (or if it is even possible) to match the starting tag with the ending tag when that text is variable.</p>
  
  <p>I thought I had seen some kind of referencing system in regular expressions before where you can use the dollar sign and a number, but I don't know if you can use this within the search itself.</p>
  
  <p>I originally thought that perhaps I could write something like: <code>\{(.*?)\}(someExpression)\{\/${1}\}</code> but I have no idea if this would actually work or if it is possible (let alone if it is correct).</p>
  
  <p>I hope this question makes sense as I'm not really sure how to ask it.
  Mainly because like I said I don't know if this has a name, if it is possible and I am also a total beginner at regular experessions.</p>
  
  <p>And if it makes any difference the language I am doing this is in PHP with the <code>preg_replace_callback</code> function.</p>
  
  <p>Any help would be greatly appreciated.</p>