 <p>Use <strong>String</strong> replaceAll method with following pattern:</p> <p><strong>Pattern</strong></p> <pre><code>(?&lt;=\.).*(?=\?) </code></pre> <p><strong>Code</strong></p> <pre><code>String s = "blah.t!@Z8-st?asdas"; System.out.println(s.ReplaceAll("(?&lt;=\\.).*(?=\\?)", "")); </code></pre>