Match a comma followed by a newline with a regular expression

Posted by MarathonStudios on Stack Overflow See other posts from Stack Overflow or by MarathonStudios
Published on 2011-01-05T22:51:00Z Indexed on 2011/01/05 22:53 UTC
Read the original article Hit count: 167

Filed under:
|

I have a comma delimited list I want to import into a database, and in some cases the last item is blank:

item1, item2, item3
item1, item2,
item1, item2,

I'd like to replace all of these empty columns with a placeholder value using a regexp

item1, item2, item3
item1, item2, PLACEHOLDER
item1, item2, PLACEHOLDER

I tried preg_replace("/,\n/", ",PLACEHOLDER\n",$csv);, but this isn't working. Anyone know what regexp would work for this?

© Stack Overflow or respective owner

Related posts about php

Related posts about regex