Say I have this string:
var results =
[{\r\n \"ninja\": \"Leonardo - $0.99\",\r\n \"data\": [[1336485655241,0.99],[1336566333236,0.99],[1336679536073,0.99],[1336706394834,0.99],[1336774593068,0.99],[1366284992043,0.99]]},
\r\n{\r\n \"ninja\": \"Donatello - $0.25\",\r\n \"data\": [[1361061084420,0.23],[1366102471587,0.25],[1366226367262,0.25],[1366284992043,0.25]]},
\r\n{\r\n \"ninja\": \"Raphael - $0.15\",\r\n \"data\": [[1327305600000,0.15], [1365583220422,0.15],[1365669396241,0.15],[1365669396241,0.15],[1365753433493,0.15],[1366284992043,0.15]]},\r\n\
r\n{\r\n \"ninja\": \"Michelangelo - $0.14\",\r\n \"data\": [1366284992043,0.14]]};
I wanted to build a dictionary that would store the names of the ninjas and their price, so that I would have:
Key \ Value
Leonardo \ 0.99
Donatello \ 0.25
Raphael \ 0.15
Michelangelo \ 0.14
So I have been reading a LOT since a few days about regex, and I don't know how it works yet. Up to now I have this line of code:
var dictNinjas = Regex.Matches(priceListValue, @"\*(\w+)=(a-zA-Z)|\*(\$(0-9))").Cast<Match>()
.ToDictionary(x => x.Groups[0].Value,
x => x.Groups[1].Value);
My comprehension was that is would first seek all words with letters a-zA-Z, then all values located right after the $ symbol. The | symbol is the grouping, so the first parameters was group 0 and the second parameter would be group 1. But this does not work.
Can anyone help me out? I'm trying hard to understand how to make this work, thank you.