I have html/text string and want to match all links-like parts of the text to real hyperlinks with A tag. For this question I'am trying to match "www.somesite.domen" pattern. But, what if the pattern is near punctuation character at the end of the sentence.
How to match pattern without very last character which is punctuation?
- www.somesite.domen.
- www.somesite.domen,
- www.somesite.domen?
- www.somesite.domen!
- www.somesite.domen/?id=1?
Here is the function I'am using for:
function make_links($text)
{
return preg_replace(
array(
'/(^|\s)(www\.[^<>\s!,]+)(!$|\s|\.|\:|\!|,|\?)/iex'
),
array(
"stripslashes((strlen('\\2')>0?'\\1<a target=\"_blank\" href=\"http://\\2\">\\2</a>\\3':'\\0'))"
),
$text
);
}
But when the '.' or '?' characters are the last in sentence, my function is taking them into the link too.
Any idea how to solve this cases? Thanks!