Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return part of string using Regex

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

like image 227
Jd_Daniels Avatar asked Oct 22 '22 03:10

Jd_Daniels


1 Answers

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);
like image 150
Jesse Smith Avatar answered Nov 03 '22 20:11

Jesse Smith