title: How to universally extract texts in between two words in Java
body: <p>How can I generally extract text in between two words (made up of special characters) like the way its done <a href="https://stackoverflow.com/a/1988340/10138416">here</a></p>
  <p>I would like to extract all texts in between <code>&quot;{one}“</code> and <code>&quot;{two}“</code></p>
  <pre><code>String input=&quot;{one} i am here fine {two} {one} hope your are also fine {two} {one} ok see you {two}&quot;;
  </code></pre>
  <p>I tried escaping the special characters in my words but it doesn’t work (i.e. using <code>&quot;(\\b\\{one\\}\\b)(.*?)(\\b\\{two\\}\\b)&quot;</code> as my regex instead of <code>&quot;(\\b{one}\\b)(.*?)(\\b{two}\\b)&quot;</code>)</p>
  <pre><code>Pattern p = Pattern.compile(&quot;(\\b\\{one\\}\\b)(.*?)(\\b\\{two\\}\\b)&quot;);
  Matcher m = p.matcher(input);
  List&lt;String&gt; matches = new ArrayList&lt;String&gt;();
  while (m.find()) {
    matches.add(m.group(2));
  }
  </code></pre>