正则表达式使用字符拆分并用不同的字符串替换第一部分

Regex split using a character and replace the first part with a different string

我有如下字符串列表:

Austria: ac.at
Bangladesh: ac.bd
Belgium: ac.be
China: ac.cn
Cyprus: ac.cy
India: ac.in

我需要得到如下列表:

$Resolved URL$ LIKE "*ac.at/*"
$Resolved URL$ LIKE "*ac.bd/*"
$Resolved URL$ LIKE "*ac.be/*"
$Resolved URL$ LIKE "*ac.cn/*"
$Resolved URL$ LIKE "*ac.cy/*"
$Resolved URL$ LIKE "*ac.id/*"

使用正则表达式替换执行此操作的最佳方法是什么?

您可以在正则表达式模式下尝试以下查找和替换:

Find:    ^.*?(\S+)$
Replace: $Resolved URL$ LIKE "*/*"

Demo

下面是对正则表达式的解释:

^          from the start of the string
    .*?    consume (but do not capture) all content
    (\S+)  up until the final collection of non word characters and capture them
$          end of the input

只需匹配您希望保留的五个字符并围绕它构建替换字符串。您可以使用以下正则表达式。

[a-z]{2}\.[a-z]{2}

替换字符串是

$Resolved URL$ LIKE "*[=11=]/*"

其中 [=12=] 是匹配的字符串(例如,"ac.at")。

Start your engine!