I want to match all lines that have any uppercase characters in them but ignoring the string A_
To add to the complication I want to ignore everything after a different string, e.g. an open comment
Here are examples of what should and shouldnt match
Matches:
Non Matches (C_ should not trigger a match)
thanks :)
Using character sets For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
In other words, square brackets match exactly one character. (a-z0-9) will match two characters, the first is one of abcdefghijklmnopqrstuvwxyz , the second is one of 0123456789 , just as if the parenthesis weren't there. The () will allow you to read exactly which characters were matched.
This should (also?) do it:
(?!A_)[A-Z](?!((?!/\*).)*\*/)
A short explanation:
(?!A_)[A-Z] # if no 'A_' can be seen, match any uppercase letter
(?! # start negative look ahead
((?!/\*).) # if no '/*' can be seen, match any character (except line breaks)
* # match zero or more of the previous match
\*/ # match '*/'
) # end negative look ahead
So, in plain English:
Match any uppercase except 'A_' and also not an uppercase if '*/' can be seen without first encountering '/*'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With