Re: not sure why regex is doing this

From: Date: Fri, 09 Jan 2004 17:23:02 +0000
Subject: Re: not sure why regex is doing this
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-174141@lists.php.net to get a copy of this message
Hi Craig, the mistake is in regex, because you replace only the pair of "," with ",NULL,"... So in case, that there are tree "," in row, there is only one pair and it means one replacing.. For example, when your string is like this: (12345,,,,) //two pair of ",," the result is (12345,NULL,,NULL,) But now - I don't know, how to change regex easily to help you... :o)) In case, that I have any idea, I will write you again :o) PJ PS: I hope, that I am right :o) "Craig" <php@lonsbury.com> píse v diskusním príspevku news:IBELIEPEJMOIMBCMOCLJAEOCCGAA.php@lonsbury.com... > Hi, > > I have a text file that I have to parse and insert into a db. > these are a couple of sample lines (they are part of the > variable $query) > > (4536,'golf tournament management',430,0,0), > (1434,'Premium golf balls',,,0), > > I have to replace the blank entries (,,) with NULLs, > and I am using this regex: > $query = preg_replace('/,\s*,/',',NULL,', $query, -1); > > after this line, only ONE of the ,, sets is replaced > by ,NULL, like this: > (4536,'golf tournament management',430,0,0), > (1434,'Premium golf balls',NULL,,0), > > So, my problem is that I have to run the regex twice to > replace both sets of ,, with ,NULL, and I really don't > want to do that. Why isn't it getting them both with the > first regex, and how should I modify it to catch them > both? > > TIA, > Craig

« previous php.general (#174141) next »