C # - How to use Regex to replace the NULL character?


I have the following string:

< \0\"\0E\0x\0t\0e\0n\0s\0i\0b\0i\0l\0i\0t\0y\0,\0v\0e\0r\0s\0i\0o\0n\0=\0\\\0\"\07\0.\00\0.\03\03\00\00\0.\00\0\\\0\"\0,\0p\0u\0b\0l\0i\0c\0K\0e\0y\0T\0o\0k\0e\0n\0=\0\\\0\"\0B\00\03\0F\05\0F\07\0F\01\01\0D\05\00\0A\03\0A\0\\\0\"\0,\0f\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0=\0\\\0\"\07\0.\00\0.\09\04\06\06\0.\01\0\\\0\"\0,\0c\0u\0l\0t\0u\0r\0e\0=\0\\\0\"\0n\0e\0u\0t\0r\0a\0l\0\\\0\"\0\"\0=\0h\0e\0x\0(\07\0)\0:\07\08\0,\0\\\0"

In notepad++ it looks something like:

I would like to replace all "NULL" instances using Regex, but I can't seem to get the correct search pattern. This is my code:

        FileInfo file = new FileInfo(path);
        string line;
        using (StreamReader reader = new StreamReader(file.FullName))
            while ((line = reader.ReadLine()) != null)
                Regex rgx = new Regex(@"^[\00|\0]");
                line = rgx.Replace(line, "");


However, this does not appear to be replacing any text. What would the correct search pattern for this be?

The problem with your regex is the ^ character which means that your regex will only look at the start of the string for the NULL character. Take it off and your code will work just fine.