Php 调整regex以在url末尾查找/
我目前有以下代码:Php 调整regex以在url末尾查找/,php,regex,url,Php,Regex,Url,我目前有以下代码: // turn any url into url bbcode that doesn't have it already - so we can auto link urls- thanks stackoverflow $URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
// turn any url into url bbcode that doesn't have it already - so we can auto link urls- thanks stackoverflow
$URLRegex = '/(?:(?<!(\[\/url\]|\[\/url=))(\s|^))'; // No [url]-tag in front and is start of string, or has whitespace in front
$URLRegex.= '('; // Start capturing URL
$URLRegex.= '(https?|ftps?|ircs?):\/\/'; // Protocol
$URLRegex.= '\S+'; // Any non-space character
$URLRegex.= ')'; // Stop capturing URL
$URLRegex.= '(?:(?<![[:punct:]])(\s|\.?$))/i'; // Doesn't end with punctuation and is end of string, or has whitespace after
$body = preg_replace($URLRegex,"$2[url=$3]$3[/url]$5", $body);
//将任何url转换为还没有url的url bbcode-这样我们就可以自动链接url-谢谢stackoverflow
$URLRegex='/(?:(?)?
它查找任何URL,并将它们转换为bbcode(基本上是自动链接URL),问题是如果一个URL的末尾有一个/,它就不会被解析
有人能告诉我如何解决这个问题吗?谢谢!反向查找中的[[:punct:][]
将匹配/
,从而防止其包含在匹配中
您可以将[[:punct:][]
替换为一个字符类,该类包含您希望防止成为最后一个字符的所有特定字符,例如[;!?:\“\”()-]
您考虑过改用a吗?另请参见尝试编辑此$URLRegex.=”(?:(?HamZa,效果很好!谢谢!@LiamDawe,欢迎您:)我回来是想说它没有得到结尾的斜杠!谢谢:D@LiamDawe.我不明白你的意思-请解释。我的意思是当我意识到事情正在发生时我会回到这里,但你已经在这里给出了答案:)