79524331

Date: 2025-03-21 00:21:12
Score: 0.5
Natty:
Report link

There are two ways to solve this problem

Consider the regex below

(?:^\s*DEBUG\s+)*(.+)

with test data

DEBUG How are you1?

DEBUG How are you2?

How are you3?

_DEBUG How are you4?

I want to filter out the string DEBUG from the beginning if present. We created two groups.

The c# code to get those value is below

string pattern = @"(?:^\s*DEBUG\s+)*(.+)";
Regex regex = new Regex(pattern);
var testInput=@"DEBUG How are you1?
DEBUG How are you2?
How are you3?
_DEBUG How are you4?";
var result = Regex.Matches(testInput,pattern,RegexOptions.Multiline);
result.Cast<Match>()
      .Select(m => m.Groups[1].Value)
      .ToList()
      .Dump();

Output:

enter image description here

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
Posted by: Hemendr