title: Use RegEx in Java to extract parameters in between parentheses
body: <p>I'm writing a utility to extract the names of header files from JSPs. I have no problem reading the JSPs line by line and finding the lines I need. I am having a problem extracting the specific text needed using regex. After looking at many similar questions I'm hitting a brick wall.</p>
  
  <p>An example of the String I'll be matching from within is:</p>
  
  <pre><code>&lt;jsp:include page="&lt;%=Pages.getString(\"MY_HEADER\")%&gt;" flush="true"&gt;&lt;/jsp:include&gt;
  </code></pre>
  
  <p>All I need is MY_HEADER for this example. Any time I have this tag:</p>
  
  <pre><code>&lt;%=Pages.getString
  </code></pre>
  
  <p>I need what comes between this: </p>
  
  <pre><code>&lt;%=Pages.getString(\"  and this: )%&gt;
  </code></pre>
  
  <p>Here is what I have currently (which is not working, I might add) :</p>
  
  <pre><code>String currentLine;
  while ((currentLine = fileReader.readLine()) != null)
  {
  Pattern pattern = Pattern.compile("&lt;%=Pages\\.getString\\(\\\\\"([^\\\\]*)"); 
  Matcher matcher = pattern.matcher(currentLine); 
  while(matcher.find()) {
  System.out.println(matcher.group(1).toString());                           
  }}
  </code></pre>
  
  <p>I need to be able to use the Java RegEx API and regex to extract those header names. </p>
  
  <p>Any help on this issue is greatly appreciated.  Thanks!</p>
  
  <p>EDIT: </p>
  
  <p>Resolved this issue, thankfully. The tricky part was, after being given the right regex, it had to be taken into account that the String I was feeding to the regex was <em>always</em> going to have  two  " / "  characters ( (/"MY_HEADER"/) ) that needed to be escaped in the pattern. </p>
  
  <p>Here is what worked (thanks to the help ;-)):</p>
  
  <pre><code>Pattern pattern = Pattern.compile("&lt;%=Pages\\.getString\\(\\\\\"([^\\\\\"]*)"); 
  </code></pre>