title: R - Regular expression to match all punctuation except that inside of a URL
body: <p>Basically, I'm looking for a regular expression to select all punctuation except for that which is inside of a URL.</p>
  
  <p>In essence, if I have the string:</p>
  
  <pre><code>This is a URL: https://test.com/ThisIsAURL !
  </code></pre>
  
  <p>And remove all matches it should become:</p>
  
  <pre><code>This is a URL https://test.com/ThisIsAURL
  </code></pre>
  
  <p><code>gsub("[[:punct:]]", "", x)</code> removes all punctuation including from URLs. I've tried using negative look behinds to select punctuation used after https but this was unsuccessful.</p>
  
  <p>In the situation I need it for, all URLs are Twitter link-style URLs <code>https://t.co/</code>. They do not end in <code>.com</code>. Nor do they have more than one backslashed slug (<code>/ThisIsAURL</code>). However, IDEALLY, I'd like the regex to be as versatile as possible, able to perform this operation successfully on any URL.</p>