I have this string that I have read from a file.
/**********************************************************************functionheaderstuff***********************************************************************************************************************/
void fn1(void)
{
b= 8;
}
/***********************************************************************functionheaderstuff***********************************************************************************************************************/
void fn2(int a, intb)
{ int c;
var = 6;
}
I want to match the function which contains the variable var which is written.
With this regex (?<=[*]{60}/)(s*w+(?: w+s*)(?=(((.*?))s*{))).*(var([^>=<!;{])*[=]{1}[^=]*?[;])
, I am matching both the functions as the .* is greedy. I need it to not match if it encounters }s*/[*]{60}
and only match if the function contains the variable being written, preferably only if the variable is not within a comment.
Negative lookahead didn't work- ((?<=[*]{60}/)s*w+(?: w+s*)(?=(((.*?))s*{)).*)(?!(s*}s*/[*]{60}))(var([^>=<!;{])*[=]{1}[^=]*?[;])
My function will start with the type of function header I shared. Finding variable being written into and identifying the function works okay.
This regex works fine if the function contains the var else it takes from the next function. What am I doing wrong here?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…