What do I have to change in this regular expression so that in both cases below it gets the text before the first colon as the "label" and all the rest of the text as the "text".
using System;
using System.Text.RegularExpressions;
namespace TestRegex92343
{
class Program
{
static void Main(string[] args)
{
{
//THIS WORKS:
string line = "title: The Way We Were";
Regex regex = new Regex(@"(?<label>.+):\s*(?<text>.+)");
Match match = regex.Match(line);
Console.WriteLine("LABEL IS: {0}", match.Groups["label"]); //"title"
Console.WriteLine("TEXT IS: {0}", match.Groups["text"]); //"The Way We Were"
}
{
//THIS DOES NOT WORK:
string line = "title: The Way We Were: A Study of Youth";
Regex regex = new Regex(@"(?<label>.+):\s*(?<text>.+)");
Match match = regex.Match(line);
Console.WriteLine("LABEL IS: {0}", match.Groups["label"]);
//GETS "title: The Way We Were"
//SHOULD GET: "title"
Console.WriteLine("TEXT IS: {0}", match.Groups["text"]);
//GETS: "A Study of Youth"
//SHOULD GET: "The Way We Were: A Study of Youth"
}
Console.ReadLine();
}
}
}