我有一組具有以下結構的網址:
https://www.example.com/img/public/vendor1/us/en/product-assets/vendor/product/green/device_230x400_a.gif
在構建這個資料結構時,我意識到我需要/image/在給定的產品名稱之后添加。產品名稱會有所不同,但斜線是固定實體,所以這應該是合適的:在 ./image/的第 11 個實體之后添加/。
換句話說,目標是:
https://www.example.com/img/public/vendor1/us/en/product-assets/vendor/product/image/green/device_230x400_a.gif
我將不勝感激任何幫助;我正在使用 Notepad 進行替換。
謝謝!
uj5u.com熱心網友回復:
您可以在正則運算式模式下使用以下查找和替換:
Find: ^(https?://(?:[^/] /){9})(.*)$
Replace: $1image/$2
這個正則運算式說:
^
( capture in $1
https?: http: or https:
// //
(?:[^\/] \/){9} match 9 path components
)
(.*) capture the remainder of the URL in $2
$
然后我們替換為在所需位置$1image/$2插入路徑組件。/image
這是一個演示。
uj5u.com熱心網友回復:
只需替換正則運算式的匹配
(?:.*?\/){11}
與$0 'image/'.
演示
$0舉行比賽。
正則運算式可以分解如下。
(?: # begin non-capture group
.*? # match zero or more characters, as few as possible (lazily)
\/ # match '/'
){11} # end non-capture group and execute it 11 times
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/429558.html
標籤:正则表达式
上一篇:洗掉特定文本后面的點
