@Charlie Gale , Welcome to Microsoft Q&A, have you considered another method without using Regex? It may be more simpler.
Please refer to the following code to use linq to remove a line which contains the certain value.
static void Main(string[] args)
{
var result = filterIDs("201");
}
public static string filterIDs(string dataIn)
{
var filteredIDs = File.ReadAllLines("1.txt");
var notincluded = filteredIDs.Where(x => !x.Contains(dataIn));
string result=string.Join("\r", notincluded.ToArray());
return result;
}
Note: Here I used txt file as the data source and you could make some changes based on your situation.
Tested result:
Hope this could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.