[Solved] Parts of string in regex


This should get you started:

var myUrl     = "wmq://aster-C1.it.google.net@EO_B2:1427/QM.0021?queue=SOMEQueue?";
var myRegex   = new Regex(@"wmq://(.*?)@(.*?)\?queue=(.*?)\?");
var myMatches = myRegex.Match(myUrl);

Debug.Print(myMatches.Groups[1].Value);
Debug.Print(myMatches.Groups[2].Value);
Debug.Print(myMatches.Groups[3].Value);

But you may need to change it a bit for variations in the url.

There are proper tutorials on the web to explain Regex, but here is some quick info:

  • @ before a string “” in C# avoids the need to escape the blackslashes.
  • (brackets) are the capture groups, so “() ()” becomes groups[1] groups[2].
  • .*? means match anything, but do an ungreedy minimal match.
  • \? the backslash says match the question mark instead of it being a special character.

solved Parts of string in regex