I can't figure out how to match comments but not html hex in regex. For example I want the script to match
#I'm a comment, yes I am
but not
#FF33AF
I can't figure out how to match comments but not html hex in regex. For example I want the script to match
#I'm a comment, yes I am
but not
#FF33AF
You could use negative lookahead. From the python documentation:
(?!...)
Matches if ... doesn’t match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match 'Isaac ' only if it’s not followed by 'Asimov'.
Well, the obvious regex is going to be something like:
(?m-:^\s*#(?![0-9A-Fa-f]{6}).*$)
This gives you all lines that start with a '#'. From your post your not very specific but I think that is what your looking for.
Updated:
Corrected to only allow the six:
(?m-:^\s*#(?![0-9A-Za-z]{6}\s*$).*$)
To do the job right you need a parser not a regular expression matcher. For example, is "#decade" a comment or a color name? You can't know without a little context.