I am trying to use (?<!\\)# to match #s without a \ in the front (the task is to escape the unescaped #s in a string). This regex works on several online regex validators. However it doesn't work with the python re module. I also tried escaping the symbols in the regex, but it either produces errors or does not produce the expected output.
re.sub("(?<!\\)#","\#",'asd\#fh## #')
How can I modify this regex so it can produce the output asd\\#fh\\#\\# \\#(The output has \s escaped so there are double \\)?
 
    