using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
private readonly ConcurrentBag<string> _objectifiableMatches = new();
public async Task<ConcurrentBag<string>> GetKeywordMatchesAsync()
var keywords = new List<string>()
var watch = System.Diagnostics.Stopwatch.StartNew();
var splittingTasks = new List<Task>();
foreach (var kw in keywords)
var keyword = kw.ToUpper();
splittingTasks.Add(Task.Run(() => SplitMatches(keyword)));
await Task.WhenAll(splittingTasks);
return _objectifiableMatches;
public void SplitMatches(string keyword)
var patternObject = $@"\/begin {keyword}[\s\S]+?\/end {keyword}";
var regexObject = new Regex(patternObject);
var Matches = regexObject.Matches(_content);
Parallel.ForEach(Matches, m =>
var replacedQuotes = m.Value.Replace($"\"", "'");
_objectifiableMatches.Add(replacedQuotes);
await demo.GetKeywordMatchesAsync();