I have a large text from file (usually an html fine, but it can be any text). I need to replace a part of text with a string value.
string FullText = GetTextFromFile(filename);
string OldString = "<div class=\"main\">some text here</div>";
string NewString = "<div class=\"main replaced\" id=\"someid\">some new text here</div>";
Now I did a string replace
FullText=FullText.replace(OldString,NewString);
This does not always work. What I found the replace fails because the string which I need to find/replace, is not an exact match. Eg: in this case, the part of the fulltext might be
...<div class='main'> some
text here</div>...
note the single quotes instead of double quotes, and the number of spaces between the words. So, a basic string replace is not possible in this case.
My question: 1. is it possible to do a regex replace in this case? 2. if possible, what is the regex I need to use to get the correct sentence/part of the code?
In short, I need the regex replace to work irrespective of number of spaces/new line, or single/double quotes.