title: Use replaceAll() in Java to replace symbol using original leading and trailing character(s)
body: <p>I want to replace all <code>@</code> symbols that exist after a <code>(</code> or a <code>' '</code>, and that exist before any of the following characters <code>[.,;?!:) ]</code>. I want to replace them with a double quote <code>"</code> symbol, but I want to keep the original leading and trailing characters.</p>
  
  <p>For example, if I have the following text:</p>
  
  <pre><code>Hello @world@!
  </code></pre>
  
  <p>I want it to become:</p>
  
  <pre><code>Hello "world"!
  </code></pre>
  
  <p>But if I have the following text:</p>
  
  <pre><code>user@email.com
  </code></pre>
  
  <p>It <strong>shouldn't</strong> change...</p>
  
  <pre><code>user@email.com
  </code></pre>
  
  <p>I currently have the following code:</p>
  
  <pre><code>String text = "Hello @world@!";
  text = text.replaceAll("[ (]@[.,;?:) ]","\"");
  </code></pre>
  
  <p>This replaces the <code>@</code> symbol with double quotes, but it also removes the leading and trailing characters, which I don't want. How can I preserve the leading and trailing characters?</p>