I am currently trying to parse out comments in a particular format using JavaScript. While I have a basic understanding of regular expressions, with this one I seem to have reached my current limit. This is what I am trying to do:
The comments
//
This is a
multiline comment
Code here
//
This is another
comment
Again, code here
For the Regex, it currently looks this like this:
\/\/\n(\s+[\s\S]+)
\/\/\nmatches the//sequence including the new line.- Since I am interested in the comments, I am opening a capture group.
\s+matches the indentation. I could probably be a bit more precise by only accepting tabs or spaces in a particular count – for me this is not relevant[\s\S]is supposed to match the actual words and and spaces between the words.
This seems to currently match the whole file, which is not what I want. What I now can't wrap my head around is how to solve this?
I think my problem is related to me not knowing how to think about regexes. Is it like a program that matches line per line, so I need to work more on the quantifiers? Or is there maybe a way to stop at lines only consisting of a newline? When I try to match for the newline character, I of course receive matches at each line ending, which is not helpful.