RosettaCodeData/Task/Strip-comments-from-a-string/Mathematica/strip-comments-from-a-strin...

5 lines
201 B
Plaintext

a = "apples, pears # and bananas
apples, pears ; and bananas";
b = StringReplace[a, RegularExpression["[ ]+[#;].+[\n]"] -> "\n"];
StringReplace[b, RegularExpression["[ ]+[#;].+$"] -> ""] // FullForm