I need a regex that matches a specific capturing group which falls inside a multiline comment /* ... */.
In particular I need to find PHP variable definitions inside multiline comments
for example:
/* other code $var = value1 */
$var = value2 ;
/*
other code
$var = value3 ;
other code
*/
must match only the two occurences of '$var =' inside the comments but not the one outside the comment.
for the above example I wrote a regex that uses unrestricted lookbehind, like this
(?<=[/][\*][^/]+)(\$var) | (?<=[/][\*][^\*]+)(\$var)
but this regex fails in case it finds both charachter * and / even if they are APART from one another, between the comment opening tag '/*' and $var, which is not the desired bahaviour:
for example it fails in the case:
$var = .... ;
/*
other * code /
$var = .... ;
other code
*/
bacause it finds both '*' and '/' even if it's not the comment closing tag.
The key point is that I cannot negate a token which is combination of two charachter, but can only negate them one by one: [^*] or [^/].
...furthermore I cannot use the token [\s\S] instead of [^/] and [^*] because it would select $var out of comments preceded by a previous block of comment.
Any ideas? Is it even possibile with normal regex to achieve this? Or would I need something different?