Return part of string using Regex

77 Views Asked by At

I'm looking for some regex to retrieve the GUID from the following URL

GetUploadedUserAudioIdfriendlyName=eb0c5663-a9c3-4321-8c0e-5ffbfb3139fc

I've so far got

GetUploadedUserAudioId\?friendlyName=([A-Fa-f0-9-]*)

but this is returning the full url

This is the image of where the expressions are to give you an idea of what I am trying to do. enter image description here

1

There are 1 best solutions below

0
Jesse Smith On

Don't use a regex for this.

Assuming you're using C#.NET, use the static ParseQueryString() method of the System.Web.HttpUtility class that returns a NameValueCollection.

Uri myUri = new Uri("http://www.example.com?GetUploadedUserAudioIdfriendlyName=eb0c5663-a9c3-4321-8c0e-5ffbfb3139fc");
string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("param1");

Check this documentation


EDIT: If you want it as a Guid after that, then cast it to one:

var paramGuid = new Guid(param1);