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 = "
<?php
/* Multi-line
comment */
$var = 1;
"
new_txt = re.sub(r'/*[.
]*?*/', '', txt, flags=re.MULTILINE)
print("
=========== TXT ============")
print(txt)
print("
=========== 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 ?
See Question&Answers more detail:os