Skip to main content
The 2024 Developer Survey results are live! See the results
added 40 characters in body
Source Link
Mud
  • 28.7k
  • 11
  • 60
  • 97
string input = "foo:Foobarius Maximus Tiberius Kirk bar:Barforama zap:Zip Brannigan"; 

foreach (Match match in Regex.Matches(input, @"(\w+):([^:]+)(?![\w+:])"))
{
   Console.WriteLine("{0} = {1}", 
       match.Groups[1].Value, 
       match.Groups[2].Value
      );
}

Gives you:

foo = Foobarius Maximus Tiberius Kirk
bar = Barforama
zap = Zip Brannigan
string input = "foo:Foobarius Maximus Tiberius Kirk bar:Barforama zap:Zip Brannigan";
foreach (Match match in Regex.Matches(input, @"(\w+):([^:]+)(?![\w+:])"))
{
   Console.WriteLine("{0} = {1}", match.Groups[1].Value, match.Groups[2].Value);
}

Gives you:

foo = Foobarius Maximus Tiberius Kirk
bar = Barforama
zap = Zip Brannigan
string input = "foo:Foobarius Maximus Tiberius Kirk bar:Barforama zap:Zip Brannigan"; 

foreach (Match match in Regex.Matches(input, @"(\w+):([^:]+)(?![\w+:])"))
{
   Console.WriteLine("{0} = {1}", 
       match.Groups[1].Value, 
       match.Groups[2].Value
      );
}

Gives you:

foo = Foobarius Maximus Tiberius Kirk
bar = Barforama
zap = Zip Brannigan
Source Link
Mud
  • 28.7k
  • 11
  • 60
  • 97

string input = "foo:Foobarius Maximus Tiberius Kirk bar:Barforama zap:Zip Brannigan";
foreach (Match match in Regex.Matches(input, @"(\w+):([^:]+)(?![\w+:])"))
{
   Console.WriteLine("{0} = {1}", match.Groups[1].Value, match.Groups[2].Value);
}

Gives you:

foo = Foobarius Maximus Tiberius Kirk
bar = Barforama
zap = Zip Brannigan