I have a regex which I am using to remove everything after a specific character, semi-colon.
var regex = new Regex(@";(.*)", RegexOptions.Singleline);
tb.Text = regex.Replace(tb.Text, "");
It seems to work fine, but at times it removes the entire text of the text box. For example all of this code is removed:
;fgkdfgdfgd
;dfgdfkghdfgdf
;sdgfsdfsdfsdf
;dfgdfgdfg
#dont remove this ;fgdfgdfg
the “#dont remove this” should stay intact because it isn’t after the semi-colon, but it doesn’t? Is something wrong with my regex?
The idea is to remove or trim all comments from a file.
try (UPDATE after comment):
This should run faster than the Regex too…