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

5 lines
201 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
a = "apples, pears # and bananas
apples, pears ; and bananas";
b = StringReplace[a, RegularExpression["[ ]+[#;].+[\n]"] -> "\n"];
StringReplace[b, RegularExpression["[ ]+[#;].+$"] -> ""] // FullForm