Problem with searching for strings with identical parts
Posted: Sun Dec 25, 2011 10:33 am
I'm working on my syntax highlighter which some of you may have helped me debug a few months ago. Getting around to highlighting CSS, and I've run into a snag in the regex that finds all "value" keywords (I guess that's what you'd call them; they're the ones on the right side of the colon when you're defining a property.) Examples of these are "purple", "inline-block", "monospace", etc.
Anyway, I wrote up this regex pattern for recognizing if these strings fall after a colon and before a semi colon (along with sans-serif and serif, I have all other options for the value keywords, but that would make it unreadable).
[syntax]*(:)([^;]+)?(sans-serif|serif)([^A-Za-z0-9])?*[/syntax]
Anyway, I've hit a snag when trying to get it to match and return both "sans-serif" and "serif." Even when it finds "sans-serif", it matches "sans-" in the pattern ([^;]+)?, and then "serif" matches the actual keyword search.
Any suggestions on how to fix this while also keeping the conditional that the keyword is between a colon and a semicolon, with any sort of property, digit, color, etc values in between?
I.e, it's supposed to match something like
[syntax]font-family:"Helvetica", "Arial", sans-serif;[/syntax]
Thanks!
Anyway, I wrote up this regex pattern for recognizing if these strings fall after a colon and before a semi colon (along with sans-serif and serif, I have all other options for the value keywords, but that would make it unreadable).
[syntax]*(:)([^;]+)?(sans-serif|serif)([^A-Za-z0-9])?*[/syntax]
Anyway, I've hit a snag when trying to get it to match and return both "sans-serif" and "serif." Even when it finds "sans-serif", it matches "sans-" in the pattern ([^;]+)?, and then "serif" matches the actual keyword search.
Any suggestions on how to fix this while also keeping the conditional that the keyword is between a colon and a semicolon, with any sort of property, digit, color, etc values in between?
I.e, it's supposed to match something like
[syntax]font-family:"Helvetica", "Arial", sans-serif;[/syntax]
Thanks!