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.
Matching Empty MySQL Query
Moderator: General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Re: Matching Empty MySQL Query
Add an asterisk which is the quantifier
http://java.sun.com/docs/books/tutorial ... quant.html
http://java.sun.com/docs/books/tutorial ... quant.html
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Re: Matching Empty MySQL Query
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?
Any more ideas?
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: Matching Empty MySQL Query
Actually you want the plus + quantifier, not the asterisk * (the asterisk will match *zero* items - you want at least one!) Try this one:
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!
Code: Select all
if (preg_match('/(?:\\'\\', )+(?:\\'\\')?/', $contents)) {
# Successful match
} else {
# Match attempt failed
}
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Re: Matching Empty MySQL Query
Thanks so much, its working now!