๖̶̶̶ζ͜͡SuperPyroManiac
๖̶̶̶ζ͜͡SuperPyroManiac
Explore posts from servers
SIASapphire - Imagine a framework
Created by ๖̶̶̶ζ͜͡SuperPyroManiac on 11/27/2024 in #discordjs-support
Property 'send' does not exist on type *channel types*
No description
4 replies
CC#
Created by ๖̶̶̶ζ͜͡SuperPyroManiac on 10/20/2023 in #help
❔ Convert regex match groups into parameters
So I have a program that is checking for common errors in a log, it uses regex to capture them, then also groups some information in them. I then match them up with a solution which has some {#} parameters which I replace with the groups. Right now im using a gross string.Replace() method which is being inconsistent so i'd rather use the parameters correctly, issue is I don't know how many parameters or groups there are depending on the match.
foreach (var error in errorData)
{
var errregex = new Regex(error.Regex);
var errmatch = errregex.Match(wholeLog);
if (errmatch.Success)
{

for (var i = 0; i <= 10; i++)
{
error.Solution = error.Solution.Replace("{" + i + "}", errmatch.Groups[i].Value);
}
if (log.Errors.All(x => x.ID != error.ID)) log.Errors.Add(error);
}
}
foreach (var error in errorData)
{
var errregex = new Regex(error.Regex);
var errmatch = errregex.Match(wholeLog);
if (errmatch.Success)
{

for (var i = 0; i <= 10; i++)
{
error.Solution = error.Solution.Replace("{" + i + "}", errmatch.Groups[i].Value);
}
if (log.Errors.All(x => x.ID != error.ID)) log.Errors.Add(error);
}
}
error is an object that contains the regex, solution, and unique ID. errorData is a list of said errors.
35 replies