2015-04-17 10 views
1

我有很多這樣的文本:正則表達式 - 複製HTML鏈接,裝上去後

<a href="https://mega.co.nz/#![RandomThings1]" target="_blank">[RandomThings2] [<span style="color:#008000;">[RandomThings3]</span>]</a> 

我想改變這些成這樣:

<a href="https://mega.co.nz/#![RandomThings1]" target="_blank">[RandomThings2] [<span style="color:#008000;">[RandomThings3]</span>]</a> <a href="http://no.refer.co/?link=https://mega.co.nz/%23![RandomThings1]" target="_blank">NoRefer</a> 

我怎樣才能做到這一點?

+0

什麼**語言/編輯**您使用的? – hwnd

+0

https://wordpress.org/plugins/search-regex/screenshots/ –

+0

你是否試圖在** RandomThings3 **之後添加其他鏈接? –

回答

0

由於regex flavor in Search Regex WordPress plug-in是PHP,你可以試試下面的正則表達式,假設你真的有在方括號內([RandomThings1])的任意文本:

(<a\s+[^>]*?href="[^"]*#!(\[.*?\])"[^>]*?>[^<>]*?<span[^>]*?>[^<>]*?<\/span>[^<>]*?<\/a>) 

替換$1 <a href="http://no.refer.co/?link=https://mega.co.nz/%23!$2" target="_blank">NoRefer</a>

這是demo

PHP代碼:

$re = "/(<a\\s+[^>]*?href=\"[^\"]*#!(\\[.*?\\])\"[^>]*?>[^<>]*?<span[^>]*?>[^<>]*?<\\/span>[^<>]*?<\\/a>)/"; 
$subst = "$1 <a href=\"http://no.refer.co/?link=https://mega.co.nz/%23!$2\" target=\"_blank\">NoRefer</a>"; 
$result = preg_replace($re, $subst, $str); 
+0

@Downvoter:我不知道你發現了什麼錯,請報告。只是downvoting即將離開你沒有代表:) –

+0

這不是我,我會測試正則表達式 –

+0

正則表達式的工作? –