Remove text within a symbol including symbol

I have a project where I’m trying to read all files in a folder and remove specific text between the given symbol.
I have a text file that contains text within #! and I would like to remove all text within #!
What I have so far,

The expression I have is : System.Text.RegularExpressions.Regex.Replace(txtinput,"(?<=#!).*(?=#!)"," ")

The current output I get,


thanks for anyone who can help

I would suggest to look for finding the reason for this behaviour here by the statement explanation (taken from regex101)


Maybe this helps for rewriting the statement

Give a try by using an ungreedy approach as below:


Thank you it worked. Thanks for sharing the regex101 as well.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.