gpt4 book ai didi

regex - 这种负面回顾是如何运作的?

转载 作者:行者123 更新时间:2023-12-02 07:29:00 25 4
gpt4 key购买 nike

此代码片段来自《精通正则表达式》一书。我无法理解带有负面回顾的最后一部分(注释 # Not allowed to end with [.,?!] )。该表达式如何从 http://www.google.com/foo!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.

最佳答案

不会。它位于匹配可选路径的表达式的一部分,并且由于 http://www.google.com 中没有路径,它不会有任何效果。

关于regex - 这种负面回顾是如何运作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24139681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com