Reputation: 1159
I need to use a regex will determine if a single line of python code contains an illegal char '$'. But its allowed to appear in a comment or as part of a string. Meaning:
"legal char $" illegal $ #legal $
The above line should fail because it has a $ that isn't part of a string or a comment. If I remove it, and get
"legal char $" legal #legal $
This line should pass.
Upvotes: 0
Views: 185
Reputation: 8218
Illegal: Check for a .*$.*#?
after creating a temporary string by using re.sub to replace \".*?\" in the line with an empty string.
Legal: not Illegal :) or [^$]*#?
Upvotes: 1