Matching Empty MySQL Query

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Matching Empty MySQL Query

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Matching Empty MySQL Query

Post by josh »

Add an asterisk which is the quantifier
http://java.sun.com/docs/books/tutorial ... quant.html
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: Matching Empty MySQL Query

Post 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?
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Matching Empty MySQL Query

Post 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!
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: Matching Empty MySQL Query

Post by tecktalkcm0391 »

Thanks so much, its working now!
Post Reply