I’m using SED to remove C-Style comments.
Here is the command I’m using:
sed s:[/][*].*[*][/]::g
There 2 cases I can’t figure out:
First:
int x /* comment */ = 1; /* comment */
output:
int x
Second: multi-line comment
/* first line
second line */
Output:
/* first line
second line */
The first problem is with the .* in the middle as the pattern matching is greedy and once the first “/” is matches [/][*], the inner comment expression match . and the ending comment expression matches the ending the [*][/].
Now the problem with the second is “.” doesn’t match new line character but if i put a new line character the following thing happens.
input:
int x;
/* comment */
x = 1;
/* comment */
output:
int x;
Can some tell me how to make closing tags are matched not consumed by .* or [\s\S]*?
This is one Regex I could come up with :
\/\*(.*?)\*\/Input :
Output is: