簡體   English   中英

正則表達式從URL鏈接獲取名稱

[英]Regular expression to get the Name from URL link

我在SharePoint 2010中有一個Hyperlink字段(aka列)。

說它叫做SalesReportUrl 網址看起來像:

http://portal.cab.com/SalessiteCollection/October2012Library/Forms/customview.aspx

超鏈接字段將值存儲在兩個字段(鏈接和描述)中。

如果我想將10月October2012Library從網址中October2012Library ,RegEx會是什么?

我試過這個,但它肯定不起作用:

@"<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>";

我也嘗試過:

^(.*?/)?Forms/$ 

但沒有運氣。

我認為sharepoint存儲超鏈接如下:

http://portal.cab.com/SalessiteCollection/October2012Library/Forms/customview.aspx, some description

看起來這有一個解決方案。 但是什么是語法子字符串獲取列表或庫名稱? https://sharepoint.stackexchange.com/questions/40712/get-list-title-in-sharepoint-designer-workflow

怎么樣(丹尼爾建議):

string url = @"http://portal.cab.com/SalessiteCollection/October2012Library/Forms/customview.aspx";
Uri uri = new Uri(url);
if(uri.Segments.Length > 2))
    Console.WriteLine(uri.Segments[2]); // will output "October2012Library/"

你可以添加.Replace("/", string.Empty)如果你想擺脫“/”

Console.WriteLine(uri.Segments[2].Replace("/", string.Empty));

嘗試使用這個new RegEx("SalessiteCollection/(.+?)/Forms").match(<urlString>).groups[1].value

雖然這是一個粗略的答案,但您可能需要進行一些修正,但我希望您理解我要解釋的內容。

HTTP:// [^ /] + / [^ /] + /([^ /] +)/

match的組[1]是你需要的值。 它獲取了url中的第3部分(除以/)。 如果你需要確保它后跟其他部分,即表格,最后加上它。

也許這個?

http:\/\/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}\/[a-zA-Z]*\/([a-zA-Z0-9]*)\/

http://rubular.com/r/LuuuORPRXt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM