これから削除する必要があります: http://example.com/media/catalog/product/cache/1/thumbnail/56x/9df78eab33525d08d6e5fb8d27136e95/i/m/images_3.jpg product/ と /i の間のすべてをhttpのままにします://example.com/media/catalog/product/i/m/images_3.jpg正規表現または c# を使用します。これらは、クローラー アプリのオプションです。助けてください。
2 に答える
1
var input = "http://example.com/media/catalog/product/cache/1/thumbnail/56x/9df78eab33525d08d6e5fb8d27136e95/i/m/images_3.jpg";
var re = new Regex("^(.+/product)/.+(/i/.+)$");
var m = re.Match(input);
if (!m.Success) throw new Exception("does not match");
var result = m.Groups[1].Value + m.Groups[2].Value;
//result = "http://example.com/media/catalog/product/i/m/images_3.jpg"
于 2013-10-25T14:41:55.620 に答える
0
string str = "http://example.com/media/catalog/product/cache/1/thumbnail/56x/9df78eab33525d08d6e5fb8d27136e95/i/m/images_3.jpg";
int prodIndex = str.IndexOf("/product/");
int iIndex = str.IndexOf("/i/");
string newStr = str.Substring(0, prodIndex + "/product/".Length)
+ str.Substring(iIndex + 1);
正規表現を使用したより一般的な例を次に示します。これは、次のようになると想定するのではなく、32 文字のハッシュの後の部分を探すだけです/i/
。
string str = "http://example.com/media/catalog/product/cache/1/thumbnail/56x/9df78eab33525d08d6e5fb8d27136e95/i/m/images_3.jpg";
var match = Regex.Match(str, @"(.*/product/).*/.{32}/(.*)");
var newStr = match.Groups[1].Value + match.Groups[2].Value;
于 2013-10-25T14:22:14.500 に答える