0

I'm parsing some mans with a python script and I'm trying to exclude all the text that's commented. So I thought about regex and made the following bit of code :

text = re.sub(r' (?s)/\*(.*)\*/', "", text)

At first everything seemed to work fine unfortunately what it does isn't exactly what I thought it would do :

Initial text :

some text 1
/* a comment */
some text 2
/* a comment */
some text 3

My expected result was :

some text 1
some text 2
some text 3

But it actually is :

some text 1
some text 3

Instead of removing the to occurrences of

/* comment */

it removed from the first /* to the last */ so :

/* comment */
some text 2
/* comment */

How can I fix it so it removes each occurrences instead of a big chunk of interesting text?

ashtrail
  • 93
  • 2
  • 9

0 Answers0