title: Stopping at the first occurrence of a pattern and searchable the next line in JavaScript
body: <pre><code>function fun() {
      var temp = document.getElementById('DIV2').innerHTML;
      var str = temp;
      var res = str.replace(/(\s(\S*m)\s)/gi, ' &lt;span class="red"&gt;$1&lt;/span&gt; '); // 0.5 -- 1m -- etc 
      var res2 = res.replace(/\s(\S*metre)\s/gi, '&lt;span class="red"&gt;$1&lt;/span&gt; '); // 1meter 2meter
      var res3 = res.replace(/\s(\S\s*metre)\s/gi, '&lt;span class="red"&gt;$1&lt;/span&gt; '); // 1 meter 2 meter
      document.body.innerHTML = res3;
  }
  </code></pre>
  
  
  
  <pre><code>&lt;body&gt;
      &lt;div id="text"&gt;
      The Basic High Speed HDMI 0.5m Cables with Ethernet are 0.5m suitable for use with HDMI.
      Home Theater, 1m Games Consoles (including Nintendo Wii U), 1m Blu-rays, Cable or Satelite 1m boxes and Projectors. 
      HDMI Cables provides the most reliable digital signal transfer and the purest picture. 
      &lt;/div&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The above code matches <code>"0.5m, 1m, 1 metre"</code> etc. in a string but it searches for all the occurrence in a line I wanted to make stop at the first occurrence of the pattern and continue at the next line.</p>
  
  <p>Can anybody help?</p>