Page 1 of 1

Matching Empty MySQL Query

Posted: Sat Feb 20, 2010 5:16 pm
by tecktalkcm0391
How can I make a regular expression to match whenever there is a ('', '', '', '') in a string. There can be as many '', in a row and it would match it... so it would match ('', '') and ('', '', '', '', '', '', '') as well as ('', '', '', '')

Thanks so much! I just can't figure it out.

Re: Matching Empty MySQL Query

Posted: Sat Feb 20, 2010 6:54 pm
by josh
Add an asterisk which is the quantifier
http://java.sun.com/docs/books/tutorial ... quant.html

Re: Matching Empty MySQL Query

Posted: Sun Feb 21, 2010 10:50 am
by tecktalkcm0391
I tried adding an asterisk, and it doesn't seem to be working right. When i use preg_match and have it return matches, it only shows two matches, even if there are multiple matches of '', possible...

Any more ideas?

Re: Matching Empty MySQL Query

Posted: Sun Feb 21, 2010 11:24 am
by ridgerunner
Actually you want the plus + quantifier, not the asterisk * (the asterisk will match *zero* items - you want at least one!) Try this one:

Code: Select all

if (preg_match('/(?:\\'\\', )+(?:\\'\\')?/', $contents)) {
    # Successful match
} else {
    # Match attempt failed
}
 
Note to forum administrator/moderator: To get the above code to post correctly, I had to add an extra backslash to each of the single quotes for the text within the CODE BBCode tag. There is a *BUG* in your forum software that necessitates this. I wrote a post to you guys quite a while ago about this issue in the: CODE tag erroneously strips backslash from single quote thread but as of yet have had no response at all. Please get your act together and fix this!

Re: Matching Empty MySQL Query

Posted: Sun Feb 21, 2010 11:28 am
by tecktalkcm0391
Thanks so much, its working now!