PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Jul 20, 2019 3:45 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Dec 25, 2011 11:33 am 
Offline
Forum Contributor

Joined: Tue Feb 16, 2010 6:39 pm
Posts: 254
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: [ Download ] [ Hide ]
  1. *(:)([^;]+)?(sans-serif|serif)([^A-Za-z0-9])?* 


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: [ Download ] [ Hide ]
  1. font-family:"Helvetica", "Arial", sans-serif; 


Thanks!


Top
 Profile  
 
PostPosted: Sun Dec 25, 2011 5:29 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Dec 15, 2011 2:40 pm
Posts: 85
Location: Nelson, NZ


Top
 Profile  
 
PostPosted: Wed Feb 22, 2012 8:29 am 
Offline
Forum Newbie

Joined: Fri Jan 06, 2012 2:43 am
Posts: 9


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group