title: Java Regex Remove Text Between and Including Parenthesis from String
body: <p>I am programming in Java, and I have a few Strings that look similar to this:</p>
  
  <pre><code>"Avg. Price ($/lb)" 
  "Average Price ($/kg)"
  </code></pre>
  
  <p>I want to remove the <code>($/lb)</code> and <code>($/kg)</code> from both Strings and be left with</p>
  
  <pre><code>"Avg. Price" 
  "Average Price".
  </code></pre>
  
  <p>My code checks whether a String <strong>str</strong> variable matches one of the strings above, and if it does, replaces the text inside including the parentheses with an empty string: </p>
  
  <pre><code>    if(str.matches(".*\\(.+?\\)")){
  
             str = str.replaceFirst("\\(.+?\\)", "");
      }
  </code></pre>
  
  <p>When I change str.matches to str.contains("$/lb"); as a test, the wanted substring is removed which leads me to believe there is something wrong with the if statement. Any help as to what I am doing wrong? Thank you. </p>
  
  <p><strong>Update</strong>
  I changed the if statement to: </p>
  
  <pre><code>if(str.contains("(") &amp;&amp; str.contains (")"))
  </code></pre>
  
  <p>Maybe not an elegant solution but it seems to work. </p>