Hi I am very new to regex but would like to construct something that will match on the word “Public” | “Private” | “Protected” and the following word (to grab the following word), unless the following word is not: void, string, int, bool. The bolded word matches can be any word except for the ones listed above.
Sample Matches:
- Public xyz Functionname (match)
- Public abc Functionname (match)
- Private rbc Functionname (match)
- Protected klm Functionname (match)
Sample Non-matches:
- Public void Functionname (non-match)
- Public string Functionname (non-match)
- Public int Functionname (non-match)
I got as far as this but it’s not really working properly:
^((Public)|(Private)|(Protected)).*$(?<!Void|string|int)
Try this:
After a word break, match (but don’t capture)
publicorprivateorprotected, then one or more whitespace characters, then one or more “word” characters as long as the word is notvoidorstringorintorbool.Seems to work in my tests.
Edit
To exclude matches that end with
get;orset;, it’s a bit more complicated but this appears to work:which I just like the first one with the addition of followed by any number of any character that is not followed by a
get;or aset;which ends the lineThat will match
Public xyz Functionname get; with other stuffbut notPublic xyz Functionname get;. If the former should be excluded as well, just drop the second to last$, and then a match will be discarded if there’s aget;orset;anywhere after the first section.