My string:
string str = "user:steo id:1 nickname|user:kevo id:2 nickname:kevo200|user:noko id:3 nickname";
Now I want to get the values out with Regex:
var reg = Regex.Matches(str, @"user:(.+?)\sid:(\d+)\s+nickname:(.+?)")
.Cast<Match>()
.Select(a => new
{
user = a.Groups[1].Value,
id = a.Groups[2].Value,
nickname = a.Groups[3].Value
})
.ToList();
foreach (var ca in reg)
{
Console.WriteLine($"{ca.user} id: {ca.id} nickname: {ca.nickname}");
}
I do not know how I can do it with regex that I can use nickname:(the nickname) I only want use the nickname if it has a nickname like nickname:kevo200 and noch nickname
nickname, but the value for nickname may be empty? If thenicknameis empty is this denoted asnickkname|ornickname:|What do you want to do with users, which don't have a nickname?