I want to match a block of code multiple times in a file but can’t work out the regular expression to do this. An example of the code block is:
//@debug ... // code in here ... //@end-debug (possibly more comments here on same line)
Each code block I’m trying to match will start with //@debug and stop at the end of the line containing //@end-debug
I have this at the moment:
/(\/{2}\@debug)(.|\s)*(\/{2}\@end-debug).*/
But this matches one big block from the first //@debug all the way to end of the line of the very last //@end-debug in the file.
Any ideas?
Basically your regular expression is greedy. This means the wildcard operators grab as much as they possibly can with the results you’ve seen. Just change it to non-greedy where appropriate. In your case use:
/(/{2}\@debug)(.|\s)*?(/{2}\@end-debug).*/