1
votes

I have a Hyperlink field (aka column) in SharePoint 2010.

Say it's called SalesReportUrl. The url looks like:

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

The hyperlink field stores values in two fields (the link and description).

What would be the RegEx if I want to get the October2012Library out of the Url?

I tried this but it's definitely not working:

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

I also tried:

^(.*?/)?Forms/$ 

but no luck.

I think sharepoint stores hyperlink like this:

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

Looks like this has a solution. but what's the syntax substring get the list or library name ?https://sharepoint.stackexchange.com/questions/40712/get-list-title-in-sharepoint-designer-workflow

4
have you tried the Uri class?Daniel A. White
Not sure how to use Uri class in Workflow. I am trying to get the document library name from the hyperlink column.Axiom
hmm. none worked. May I can use the substring function to extract the document library name from the hyperlink column (or field)Axiom

4 Answers

5
votes

How about this (as Daniel suggested) :

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/"

you can add .Replace("/", string.Empty) if you want to get rid of the "/"

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

try using this new RegEx("SalessiteCollection/(.+?)/Forms").match(<urlString>).groups[1].value

Though it is a rough answer, you might have to make few corrections but I hope you understand what I am trying to explain.

0
votes

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

match's group[1] is the value you need. it gets the 3rd part (divided by /) in the url. if you need make sure it is followed by other parts, i.e. forms, add it at the end.

-1
votes

maybe this?

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