title: using regex g flag in java
body: <p>Is it possible to use regex global g flag in java pattern ?</p>
  
  <p>I tried with <code>final Pattern pattern = Pattern.compile(regex,Pattern.DOTALL);</code>
  but it do not behave like global flag.</p>
  
  <p>Do we have any workaround for it in java ?</p>
  
  <p>My Regex is :<br>
  <code>private final String regex ="(public|private|protected|static|final|abstract|synchronized|volatile)\\s*([\\w&lt;&gt;\\[\\]]+)\\s*(\\w+)\\s*\\(([\\w\\s\\w,&lt;&gt;\\[\\]]*)?\\)\\s*(\\bthrows\\b)?[\\s\\w\\s,\\w]*\\{[\\n\\t]*(.+)[\\n\\t]*((return|throw){1}\\s*)(\\w*)\\s*;\\s*[\\}]";</code></p>
  
  <p>input is the file content , something like mentioned in below regex link :
  <a href="https://regex101.com/r/u7vanR/3" rel="noreferrer">https://regex101.com/r/u7vanR/3</a></p>
  
  <p>I want java pattern to find both the occurrences, but with java regex flags its just finding the first one and not both. </p>