5

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

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Jd_Daniels
  • 260
  • 2
  • 14
  • 3
    What tool/language do you use ? – Denys Séguret Aug 08 '13 at 13:48
  • And what **part** of the string do you want? – Mike Perrenoud Aug 08 '13 at 13:48
  • This question makes no sense if you don't precise how you use the regex. Try this in the console of your browser : `'GetUploadedUserAudioIdfriendlyName=eb0c5663-a9c3-4321-8c0e-5ffbfb3139fc'.match(/GetUploadedUserAudioIdfriendlyName=([A-Fa-f0-9-]*)/)` – Denys Séguret Aug 08 '13 at 13:49
  • 1
    You're halve way there. You need to get the first capture group from the result to get the part you want. – Ikke Aug 08 '13 at 13:50
  • And what is with the `\?` in your pattern? – AutomatedChaos Aug 08 '13 at 13:51
  • I only need the GUID part which is the string after the = sign. I need to use the expression in WebLoadUI so I can create a variable and pass it to another url. – Jd_Daniels Aug 08 '13 at 13:52
  • Ikke is right. Your regex gets everything that matches the entire pattern which includes the bit preceding the GUID. The GUID is caught in your first capture group which is normally accessed with a `\1` but may vary in some languages. – ydaetskcoR Aug 08 '13 at 13:52
  • what tool/language are you using.some1 can come up with better solution then using regex..so please specify it – Anirudha Aug 08 '13 at 13:58
  • Generally you're not looking for the match, your looking for a *captured group* within the match, i.e., something inside parenthesis in your regex. How you get at this depends on the language you're using. – brianmearns Aug 08 '13 at 14:03
  • FYI: You might find this site useful for testing regex: http://regex101.com/r/uC9tD2 – brianmearns Aug 08 '13 at 14:05
  • The tool is WebLoadUI. – Paul Fleming Aug 08 '13 at 14:09

1 Answers1

3

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);
Anirudha
  • 32,393
  • 7
  • 68
  • 89
Jesse Smith
  • 963
  • 1
  • 8
  • 21