此代码片段来自《精通正则表达式》一书。我无法理解带有负面回顾的最后一部分(评论 # Not allowed to end with [.,?!]
)。该表达式将如何[?!,.]
从http://www.google.com/foo!
or中删除http://www.google.com/bar\!
?
# Turn HTTP URLs into links . . .
$text =~ s{
\b
# Capture the URL to $1 . . .
(
http:// [-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info) \b # hostname
(
/ [-a-z0-9_:\@&?=+,.!/~*'%\$]* # Optional path
(?<![.,?!]) # Path not allowed to end with [.,?!]
)?
)
}{<a href="$1">$1</a>}gix;
print $text; # Finally, display the HTML-ized text.