Help with syntax highlighting regex?


So I’m trying to create a package that syntax highlights Sourcepawn files, but I’ve gotten a bit stuck with the more complicated nuances. I’m still new to Regex (and trying to learn, but it’s taking a while), and I can’t seem to get a few things to get highlighted properly even after looking in similar language packages such as the C/C++ or Java ones.

The main problem is getting colons (:) to highlight properly. Basically the something: in something:somethingElse should be tagged as a storage.type.legacy and the colon in something ? true : false should be a ternary operator. That detection works fine in most cases-really the only problem with this is in switch/case statements where the something: in case something: (or default:) are getting highlighted as storage.type.legacys, which they obviously aren’t. The colon in case 2: gets improperly highlighted as a ternary operator as well.
Current regex for storage.type.legacy: \\b([A-Za-z_]\\w*)\\b(:). I tried making this (?:^|=|(?:(?=\\s)(?<!case)(?<=\\w)))\\b([A-Za-z_]\\w*)(?<!default)\\b(:), but that broke things like _:something. The regex for keyword.control.ternary is pretty simple: \\?|:. I also tried to change that to (?:^|(?:(?=\\s)(?<!case)(?<=\\w)))\\s*[a-zA-Z_]\\w*(?<!default)(\\?|:), but that broke other stuff that I can’t remember right now.

Any help would be appreciated :slight_smile: (also, if this might belong better in a different category or website, let me know!).