I try to use the flag re.MULTILINE.
I read these posts : Bug in Python Regex? (re.sub with re.MULTILINE), Python re.sub MULTILINE caret match but it doesn't work. The code :
import re
if __name__ == '__main__':
txt = "\n\
<?php\n\
/* Multi-line\n\
comment */\n\
$var = 1;\n"
new_txt = re.sub(r'\/\*[.\n]*?\*\/', '', txt, flags=re.MULTILINE)
print("\n=========== TXT ============")
print(txt)
print("\n=========== NEW TXT ============")
print(new_txt)
The code output :
=========== TXT ============
<?php
/* Multi-line
comment */
$var = 1;
=========== NEW TXT ============
<?php
/* Multi-line
comment */
$var = 1;
But new_txt should not contains Multi-line comment. I want to get the txt without the Multi-line comment. Do you have any idea ?
re.Sflag notre.M, and place dot outside the character class. - Wiktor Stribiżew[.\n]to match anything BUT a*/right? Why not use[^\*\/]+? That would make\/\*[^\*]*\*\/match your multi line comment without flags. - Noxeus