I'm trying to use regex to extract the body of a comments block associated with a specific set of c++ functions. The comment format is well-known, as is the name of the functions. Comments start with /**
and end with */
. My problem is that the start of comments for non-matching functions matches with the end of matching functions, and I can't figure out how to stop this from happening.
Here's the regex I'm using (python):
\/\*\*([\s\S]*)\*\/\s(\bfunc_sig\b)\s*\(([\s\S]*?)\)
and a block of test code:
/**
*
*/
/**
*
*/
func_sig()
I want to match only the bottom comment block and function, but the expression matches the whole thing. I've tried thinking of a way to exclude the */
from the middle of the search, which I think would solve the problem, but I can't figure out a good way to do it. I can exclude the /
character from the bulk of the search entirely by changing the expression to
\/\*\*([^\/]*)\*\/\s(\bfunc_sig\b)\s*\(([\s\S]*?)\)
which works, but seems unnecessarily restrictive as there are valid reasons to use that character in a comment. Is there a good way to accomplish what I'm trying to do?