0

Im searching multiple text files and there are some lines missing which I'm trying to replace it with "NO DATA"

var GetNotes = new Regex(@"(?<=[A-Z0-9/jfc]</B>)([\s\Sa-z]*?[\s\S])(?=<tr><td>|<tr class=disabled>|</table><h4 class|[£])").Matches(set);
foreach (var Notes in GetNotes)
{
    String NotesAtLine1 = File.ReadLines(FractionTwoData).ElementAtOrDefault(NotesPositionLine);
    string NotesToString = Notes.ToString();
    string replacement = Regex.Replace(NotesToString, @"\t|\n|\r", "");
    File.AppendAllText(NotesData, NotesAtLine1 + replacement + Environment.NewLine);
    NotesPositionLine++;
    if (DebugChechBox.Checked == true)
    {
        Console.WriteLine("Notes are " + replacement);
        NotesBox.Text = replacement;
    }
}

if it finds my regex it works fine, but how do I get it to do something if it doesn't exist?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
Sean Probyn
  • 123
  • 5
  • It looks like you are trying to parse HTML with regex. This is a very bad idea. Use HTML parser instead. – Sergey Kalinichenko Oct 22 '16 at 22:10
  • can it not be done, all the rest of it works fine as its only a basic HTML and ive got them all on HDD, I don't know how to use a parser – Sean Probyn Oct 22 '16 at 22:13
  • @SeanProbyn `I don't know how to use a parser` Now it is a good time to learn it. – L.B Oct 22 '16 at 22:19
  • ive got a few CSS selectors wrote down which I used from a downloaded program but I want to make a program that I can use them in but don't know how to. Where can I get an example from or where would I start so I can do it? – Sean Probyn Oct 22 '16 at 22:23
  • can anybody tell me why its a bad idea or if it can be done? – Sean Probyn Oct 22 '16 at 22:57
  • 1
    http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454. TL;DR: HTML is not a regular language and regex is not sophistaced enough to parse HTML – 3ocene Oct 23 '16 at 06:06

0 Answers0