我想捕獲檔案中的所有 URL,但不是來自 google、bscscan、github 等。
到目前為止,我有這個正則運算式作業
(www|http:|https:) [\W] (?!bscscan|google|binance|t\.me)[\w]
應用于本段時
https://bscscan.com testing123
website: https://www.yahoo.com
another one www.bing.com is great
www.binance.org
http://bob.bscscan.com
https://twitter.google.com
https://google.twitter.com
https://t.me/rawr omg
它只匹配
1) https://www
2) www.bing
3) http://bob
4) https:/twitter
但我希望它匹配
https://yahoo.com
www.bing.com
所需的修復
#1) 包括整個 URL 鏈接。
#2) 省略鏈接中任何提及否定前瞻詞的 URL。
uj5u.com熱心網友回復:
利用
\b(?:www\.|https?:)(?!\S*\b(?:bscscan|google|binance|t\.me)\b)\S
請參閱正則運算式證明。
解釋
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
(?: group, but do not capture:
--------------------------------------------------------------------------------
www 'www'
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
http 'http'
--------------------------------------------------------------------------------
s? 's' (optional (matching the most amount
possible))
--------------------------------------------------------------------------------
: ':'
--------------------------------------------------------------------------------
) end of grouping
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
\S* non-whitespace (all but \n, \r, \t, \f,
and " ") (0 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
\b the boundary between a word char (\w)
and something that is not a word char
--------------------------------------------------------------------------------
(?: group, but do not capture:
--------------------------------------------------------------------------------
bscscan 'bscscan'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
google 'google'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
binance 'binance'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
t 't'
--------------------------------------------------------------------------------
\. '.'
--------------------------------------------------------------------------------
me 'me'
--------------------------------------------------------------------------------
) end of grouping
--------------------------------------------------------------------------------
\b the boundary between a word char (\w)
and something that is not a word char
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
\S non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
uj5u.com熱心網友回復:
試試這個,它有足夠的運算式允許你根據它的實作方式來修改它們:
/(|www\.|http\:\/\/|https\:\/\/)(?!(bscscan|google|binance|t\.me|twitter|bob))(yahoo\.com|bing\.com)/g
這將匹配以下任何變體:
https://yahoo.com. <- your required one
www.bing.com. <- your required one
www.yahoo.com
https://bing.com
http://bing.com
bing.com <- remove the "|" before "www" if you don't want this one
yahoo.com <- remove the "|" before "www" if you don't want this one
如果你添加(https\:\/\/www\.)|(http\:\/\/www\.)那么它也將匹配https://www并且http://www
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/411017.html
標籤:
