I want to remove simple // comments in a string. My String is called input
def input = '''test //kommentar
|
|//noch einer
|
|und noch //einer'''.stripMargin()
The regex is \s*\/\/.*$ and can be tested here http://regexr.com?37ks0
In my code i have input = input.replaceAll(/\s*\/\/.*$/ , '')
But it doesn't work. Can anybody help me ?
At the very least, you need to make sure that the
$anchor is allowed to match the end of each line, not just the end of the entire string:But what if
//occur, say, in a quoted string? Or in any other circumstance where they do not mean "start of comment"?