2015-08-27 56 views

回答

1

嘗試使用記事本++與 「替換」,用表達

^(.*://)([^/]*/)([^/]*/)([^/]*/)(.*)$ 

$1$2$3$5 
+0

完美,工作就像一個魅力 –

0

代替我會做服用點是這樣的:

<?php 

$string = " http://www.website.com/content/remove-this/product"; 
preg_match_all('#http:\/\/([a-zA-Z0-9-.]*)\/([a-zA-Z0-9-]*)\/([a-zA-Z0-9-]*)\/([a-zA-Z0-9-]*)#ism',$string,$out); 
$new_string = 'http://'.$out[1][0].'/'.$out[4][0]; 
echo $new_string; 
// => http://www.website.com/content 

?> 
1

對於使用Excel的答案:

公式

=LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),4)))&MID(A1,1+FIND(CHAR(1),SUBSTITUTE(A1,"/",CHAR(1),5)),99) 

UDF(使用正則表達式)

Option Explicit 
Function Remove4th(S As String) As String 
    Dim RE As Object 
Set RE = CreateObject("vbscript.regexp") 
With RE 
    .Global = True 
    .Pattern = "^((?:.*?/){4})[^/]*/" 
    .MultiLine = True 
    Remove4th = .Replace(S, "$1") 
End With 
End Function 
相關問題