title: Regex to find web addresses in short copy
body: <p>Having a short copy I need to match all occurrences of links to websites. To keep things simple a need to find out addresses in this format:</p>
  
  <pre><code>www.aaaaaa.bbbbbb
  http://aaaaaa.bbbb
  https://aa.bbbb
  </code></pre>
  
  <p>but also I need to take care of longer www/http/https versions:</p>
  
  <pre><code>www.aaaaa.bbbb.ccc.ddd.eeee
  </code></pre>
  
  <p>etc. So basically number of subdomains is not known. Now I came up with this regex:</p>
  
  <pre><code>(www\.([a-zA-Z0-9-_]|\.(?!\s))+)[\s|,|$]|(http(s)?:\/\/(?!\.)([a-zA-Z0-9-_]|\.(?!\s))+)[\s|,|$]
  </code></pre>
  
  <p>If you test on: </p>
  
  <pre><code>this is some tex with www.somewIebsite.dfd.jhh.hjh inside of it or maybe http://www.ssss.com or maybe https://evenore.com hahaah blah
  </code></pre>
  
  <p>It works fine with exception of when address is at the very end. <code>$</code> seems to work only when there is \n in the end and it fails for:</p>
  
  <pre><code>this is some tex with www.somewIebsite.dfd.jhh.hjh
  </code></pre>
  
  <p>I'm guessing fix is simple and I miss something obvious so how would I fix it? BTW I posted regex here if yu want to quickly play around <a href="https://regex101.com/r/eL1bI4/3" rel="nofollow">https://regex101.com/r/eL1bI4/3</a></p>