你可以試試這個正則表達式。
^[^/]*/
這裏是如何做到這一點的PowerShell的。
PS C:\Users\Someone>new-variable -name address -visibility public -value "www.blabla.com/hello/apple/apple/banana/"
PS C:\Users\Someone>$address -match "^([^/]*)(/)"
PS C:\Users\Someone>($a, $b) = $matches[1], $matches[2] #save the previously matched group in other variable to protect them from being overwritten.
#$a has 'www.blabla.com'
#$b has '/'
PS C:\Users\Someone>$address -replace "$a$b", "$a-"
#address now has 'www.blabla.com-hello/apple/apple/banana/'
# ^see the change here.
你在用什麼語言? –
我需要一個PowerShell腳本即時編寫 – user2162791
你期待什麼輸出? – hwnd