Skip to content
Advertisement

Python Re.Sub Function Usage Issue

I need help with this re.sub function. For example, if I wanted to replace “string” with “abc” but I want #include <string.h> to remain the same so that the syntax does not get disturbed and all the other “string” variables get replaced with “abc”. How can I write the re.sub function?

The Python code is:

JavaScript

test_str is this

JavaScript

Advertisement

Answer

Use

JavaScript

See proof

Explanation

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement