title: Efficient String Replacement in PHP
body: <p>Is there any way to make this chunk of code more efficient? I'm not looking for someone to write my code for me, just to point me in the right direction...</p>
  
  <pre><code>    $string = preg_replace('/&lt;ref[^&gt;]*&gt;([\s\S]*?)&lt;\/ref[^&gt;]*&gt;/', '', $string);
      $string = preg_replace('/{{(.*?)\}}/s', '', $string); 
      $string = preg_replace('/File:(.*?)\\n/s', '', $string);
      $string = preg_replace('/==(.*?)\=\\n/s', '', $string);        
      $string = str_replace('|', '/', $string);
      $string = str_replace('[[', '', $string);
      $string = str_replace(']]', '', $string);
      $string = strip_tags($string);
  </code></pre>
  
  <p>The catch, however, is that the replacement has to happen in this order...</p>
  
  <p>Sample input text: </p>
  
  <pre><code>    ===API sharing and reuse via virtual machine===
  {{Expand section|date=December 2013}}
  
  Some languages like those running in a [[virtual machine]] (e.g. [[List of CLI languages|.NET CLI compliant languages]] in the [[Common Language Runtime]] (CLR), and [[List of JVM languages|JVM compliant languages]] in the [[Java Virtual Machine]]) can share an API.  In this case, a virtual machine enables [[language interoperability]], by abstracting a programming language using an intermediate [[bytecode]] and its [[language binding]]s.==Web APIs==
  {{Main|Web API}}
  When used in the context of [[web development]], an API is typically defined as a set of [[Hypertext Transfer Protocol]] (HTTP) request messages, along with a definition of the structure of response messages, which is usually in an Extensible Markup Language ([[XML]]) or JavaScript Object Notation ([[JSON]]) format. While "web API" historically has been virtually synonymous for [[web service]], the recent trend (so-called [[Web 2.0]]) has been moving away from Simple Object Access Protocol ([[SOAP]]) based web services and [[service-oriented architecture]] (SOA) towards more direct [[representational state transfer]] (REST) style [[web resource]]s and [[resource-oriented architecture]] (ROA).&lt;ref&gt;
  {{cite web
   |first       = Djamal
   |last        = Benslimane
   |coauthors   = Schahram Dustdar, and Amit Sheth
   |title       = Services Mashups: The New Generation of Web Applications
   |url         = http://dsonline.computer.org/portal/site/dsonline/menuitem.9ed3d9924aeb0dcd82ccc6716bbe36ec/index.jsp?&amp;pName=dso_level1&amp;path=dsonline/2008/09&amp;file=w5gei.xml&amp;xsl=article.xsl
   |work        = IEEE Internet Computing, vol. 12, no. 5
   |publisher   = Institute of Electrical and Electronics Engineers
   |pages       = 13â€“15
   |year        = 2008
  }}
  &lt;/ref&gt; Part of this trend is related to the [[Semantic Web]] movement toward [[Resource Description Framework]] (RDF), a concept to promote web-based [[ontology engineering]] technologies. Web APIs allow the combination of multiple APIs into new applications known as [[mashup (web application hybrid)|mashup]]s.&lt;ref&gt;
  {{citation
   |first       = James
   |last        = Niccolai
   |title       = So What Is an Enterprise Mashup, Anyway?
   |url         = http://www.pcworld.com/businesscenter/article/145039/so_what_is_an_enterprise_mashup_anyway.html
   |work        = [[PC World (magazine)|PC World]]
   |date        = 2008-04-23
  }}&lt;/ref&gt;
  </code></pre>
  
  <p>Sample output (with current script):</p>
  
  <pre><code>Some languages like those running in a virtual machine (e.g. List of CLI languages/.NET CLI compliant languages in the Common Language Runtime (CLR), and List of JVM languages/JVM compliant languages in the Java Virtual Machine) can share an API.  In this case, a virtual machine enables language interoperability, by abstracting a programming language using an intermediate bytecode and its language bindings.
  When used in the context of web development, an API is typically defined as a set of Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, which is usually in an Extensible Markup Language (XML) or JavaScript Object Notation (JSON) format. While "web API" historically has been virtually synonymous for web service, the recent trend (so-called Web 2.0) has been moving away from Simple Object Access Protocol (SOAP) based web services and service-oriented architecture (SOA) towards more direct representational state transfer (REST) style web resources and resource-oriented architecture (ROA). Part of this trend is related to the Semantic Web movement toward Resource Description Framework (RDF), a concept to promote web-based ontology engineering technologies. Web APIs allow the combination of multiple APIs into new applications known as mashup (web application hybrid)/mashups.
  </code></pre>