Page 1 of 1

Regex Pattern Help

Posted: Wed Apr 07, 2010 6:21 pm
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 :)

Re: Regex Pattern Help

Posted: Wed Apr 07, 2010 7:37 pm
by requinix
Are you reading these from a file? Because fgetcsv is easier and better than doing it yourself.