Regex Pattern Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Phix
Forum Newbie
Posts: 21
Joined: Tue Jan 12, 2010 11:50 pm

Regex Pattern Help

Post by Phix »

Hey all-

I'm having a hard time wrapping my head around the correct syntax for getting a matching (preg) regex pattern for this string (and similar):

Code: Select all

"0A","A2","13","FA","A9","218",
"31","125","43","1F","199","2B"
They're CSV entries for color palettes, and I'm trying to write a quick tool that will just display a decent amount of these files easily.

I'm trying something along the lines of

Code: Select all

/(\"[^\"]{,3}\",?)+/
...as I'd like to chunk them up by twos. The first 2 are red, next two are blue, last 2 being green. I know it's not right cause it doesnt work. I think I need to use lookaheads, but that's just slightly outside my experience with regex.

In the end I'd like

Code: Select all

Array (
   [0] => 0AA2
   [1] => 13FA
   [2] => A9218
)
..etc. Once I get the regex pattern to match two-at-a-time I can take it from there.

Thanks :)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Regex Pattern Help

Post by requinix »

Are you reading these from a file? Because fgetcsv is easier and better than doing it yourself.
Post Reply