title: how to match a specific enclosed pattern and anything in between with REGEX in JS
body: <p>I want to match a pattern like this %data% in a string.</p>
  
  <p>Although it can be easy but i need solution that can be robust for a big and multiline string. </p>
  
  <p><strong>For e.g.</strong>: i would like to match only the first and second matching %% combination and third and fourth (etc. etc.) in the following:</p>
  
  <blockquote>
    <p>this %data% is not %data that i want to % show up in the results. %
    some more demo text %</p>
  </blockquote>
  
  <p>I would like to match only the parts </p>
  
  <blockquote>
    <p>%data%</p>
  </blockquote>
  
  <p>, </p>
  
  <blockquote>
    <p>%data that i want to %</p>
  </blockquote>
  
  <p>, </p>
  
  <blockquote>
    <p>% some more demo text %</p>
  </blockquote>
  
  <p>from the above string..</p>
  
  <p><strong>I have tried:</strong> </p>
  
  <p>I was trying to use this pattern but its selecting all of it from the first % to the last % symbol..</p>
  
  <pre><code>/^\%[\s\S]*\%$/gm
  </code></pre>
  
  <p>If this question has been asked and you want to close it.. just point me in the right direction and close it if you want.. thanks.</p>
  
  <p><strong>it is not the same question as marked by many..</strong> with the title: </p>
  
  <blockquote>
    <p>Regex Match all characters between two strings</p>
  </blockquote>
  
  <p>and url: <a href="https://stackoverflow.com/questions/6109882/regex-match-all-characters-between-two-strings">url</a>
  as it is normal regular expression and not the one in JS (as JS doesn't support lookbehind) and it doesn't have the pair matching problem as mine.. hence, its completely different i think..</p>
  
  <hr>
  
  <p><strong>I would really like a good description of the RegEX</strong> if someone can provide it with the answer.. as i am not well versed in reading much complicated RegEx's, just getting used to it.. and <strong>i would also like an explanation of why my code is breaking and doesn't work</strong> to help me in future..</p>