using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
public static void Main()
var text = "[thing, fallback=]";
var fallbacks = Regex.Matches(text, @"\[([^,\[\]]+),[ ]*fallback[ ]*=([^\]]*)\]", RegexOptions.IgnoreCase).Cast<Match>()
.Where(d => d.Groups.Count == 3).Where(d => !d.Groups[1].Value.Trim().IsEmpty()).ToDictionarySafe(d => d.Groups[1].Value.Trim(), e => e.Groups[2].Value.Trim());
foreach (var f in fallbacks) {
Console.WriteLine($"key={f.Key} {f.Key.GetType()} isNull={f.Key == null}");
Console.WriteLine($"value={f.Value} {f.Value.GetType()} isNull={f.Value == null}");
public static class StringExtensionMethods {
public static bool IsEmpty(this string @string)
return string.IsNullOrEmpty(@string);
public static partial class EnumerableExtensions {
public static Dictionary<TKey, TElement> ToDictionarySafe<TKey, TElement, TSource>(
this IEnumerable<TSource> list,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector)
Dictionary<TKey, TElement> result = new Dictionary<TKey, TElement>();
foreach (TSource source in list)
result[keySelector(source)] = elementSelector(source);