title: java regular expression and replace all occurrences
body: <p>I want to replace one string in a big string, but my regular expression is not proper I guess. So it's not working.</p>
  <p><strong>Main string is</strong></p>
  <p>Some sql part which is to be replaced</p>
  <pre><code>cond =  emp.EMAIL_ID = 'xx@xx.com' AND
  emp.PERMANENT_ADDR LIKE('%98n%') 
  AND hemp.EMPLOYEE_NAME = 'xxx' and is_active='Y'
  </code></pre>
  <p><strong>String to find and replace is</strong></p>
  <p>Based on some condition sql part to be replaced</p>
  <pre><code>hemp.EMPLOYEE_NAME = 'xxx'
  </code></pre>
  <p><strong>I have tried this with</strong></p>
  <p>Pattern and Matcher class is used and</p>
  <pre><code>Pattern pat1 = Pattern.compile(&quot;/^hemp.EMPLOYEE_NAME\\s=\\s\'\\w\'\\s[and|or]*/$&quot;, Pattern.CASE_INSENSITIVE);
          
          Matcher mat = pat1.matcher(cond);
           while (mat.find()) {
                       System.out.println(&quot;Match: &quot; + mat.group());
                      cond = mat.replaceFirst(&quot;xx &quot;+mat.group()+&quot;x&quot;);
                      mat = pat1.matcher(cond);
          
          }
  </code></pre>
  <p>It's not working, not entering the loop at all. Any help is appreciated.</p>