Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    sed uses regex, regex is a context-free grammar, comments are a context. This question comes up a lot, on this site and else where. As you say the // bit is easy, but the /*…*/ is impossible. You will think you have done it, after hours of pain, and then you will try /* /* */ or // /* or /* // */ If There is a version of sed that has a comments extension, then that would work. To do it you self try awk or python Commented Apr 10, 2015 at 10:24
  • I see why it is impossible to do it only with regex. What I'm trying to do here is using special sed commands that would allow us to add loops and conditions to that lookaround. Please have a look at this for a better understanding of what commands could do. I appears possible to me to do it this way because it becomes more like a little program. Even if it's impossible, I'm still looking for a solution that would be close to it, like trying avoid simple comments without special cases like those you mentioned. Commented Apr 10, 2015 at 10:31
  • I can also add this: How do you think the compilers and the context colors on code editors are made ? They're yet able not to take commented parts into account, that is made by programmation. Sed's commands are a kind of programming languages. That is why it still appears possible to me. Commented Apr 10, 2015 at 10:33
  • Well, I know nothing about awk or python so if anything made with that would work, the solution made with those languages are very welcome. Commented Apr 10, 2015 at 10:41
  • @richard - regular expressions of the pure, mathematically-descriptive language type are context free. regexp - especially w/ back-references - is not the same thing. Commented Apr 10, 2015 at 15:32