I'm looking to create a regex which matches links which have no dots at the end. I know a FQDN always has the root dot at the end, but I'm working on a blog service. I need to process blog posts and apparently some useres finish their post with with a link and then a dot to finish their sentence.
Those texts look something like:
Example text... https://example.com/site. More text here...
The problem here is that this doesn't link to any webpage. With the help of this question I made this PHP function:
function modifyText($text) {
$url = '/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/';
$string= preg_replace($url, '<a href="$0" target="_blank">$0</a>', $text);
return $string;
}
With the example from above this code generates
Example text... <a href="https://example.com/site." target="_blank">https://example.com/site.</a> More text here...
but it should generate
Example text... <a href="https://example.com/site" target="_blank">https://example.com/site</a>. More text here...