I'm trying to use python/regex to search through lines of VBA code to determine if a certain string pattern exists but only when the string pattern is not commented out.
For example, let's say the string pattern of interest is "aaa bbb ccc" and the lines of code I have are:
'aaa bbb ccc
' aaa bbb ccc
' xxx aaa bbb ccc
'xxx aaa bbb ccc xxx
xxx ' xxx aaa bbb ccc xxx
aaa bbb ccc 'xxx
xxx aaa bbb ccc
which is assigned to the Python variable of "vbaLines". I want my code to identify line 6 and line 7.
Here's my code:
re.findall("(?i)" + "(?<!\S)" + "aaa bbb ccc" + "(?!\S)", vbaLines)
The problem with my code is that it finds 6 occurrences of the pattern (all lines except for line 1). I want my code to only identify line 6 and line 7 because these are the only two lines with "aaa bbb ccc" where "aaa bbb ccc" is not commented out.
Also, I am unfamiliar with VBA, so I do not know if I am missing additional ways in which code is commented out.