USERNAME:
PASSWORD:
Save Info!
Logging in…
This topic is 1 page long.
[ Profile | Posts | Contact ]
Posted at: 11/4/09 10:25 AM
Sign-Up: 02/27/04
Posts: 1,059
preg_match("/FROM (\w*),/", $query, $tables);
This is what I have now. I'd like to extract all the tables from the query. With this code, it only returns the first. Example:
SELECT * FROM table1,table2
This will return table 1, but not table2. How do I make it repeat the search for all the patterns? Or should I forget about regex and use string functions to extract the tables?
Posted at: 11/4/09 10:37 AM
Sign-Up: 11/02/05
Posts: 11,390
Boop
(\w*(,\w*)*)
#ngprogramming at irc.freenode.net haXe | Keel imperative | Spyro! | Thru you
Posted at: 11/4/09 10:55 AM
This doesn't seem to work at all.
Posted at: 11/4/09 12:10 PM
Sign-Up: 07/17/04
Posts: 3,072
At 11/4/09 10:55 AM, Loccie wrote: This doesn't seem to work at all.
Paste a print_r of Gusts' expression, please. He should be close.
// MustyWindows - Jump Through The Windows // AmpFusion - Where Underground Becomes Mainstream Neo Enterprise Technologies Coming soon.
Posted at: 11/4/09 12:42 PM
At 11/4/09 12:10 PM, Craige wrote: At 11/4/09 10:55 AM, Loccie wrote: This doesn't seem to work at all.Paste a print_r of Gusts' expression, please. He should be close.
Right, sorry. I totally forgot that.
/(\w*(,\w*)*)/ Array ( [0] => SELECT [1] => SELECT )
I also tried:
/FROM (\w*(,\w*)*)/ Array ( [0] => FROM Music_Artists,Music_Pictures [1] => Music_Artists,Music_Pictures [2] => ,Music_Pictures )
Posted at: 11/4/09 01:27 PM
It's a pattern to match comma-separated words, as it obviously doesn't have the FROM. Are you incapable of reading a short regexp? You added FROM and it works, take the item at 1 and split it.
Posted at: 11/4/09 03:57 PM
At 11/4/09 01:27 PM, GustTheASGuy wrote: It's a pattern to match comma-separated words, as it obviously doesn't have the FROM. Are you incapable of reading a short regexp? You added FROM and it works, take the item at 1 and split it.
I did the second one first but I was looking to get an array that already had the info I wanted. Anyway, I tried what you said and then I tried using only string functions; the string functions were a lot faster according to microtime, so I'll use those. Thanks for the regex anyway.
Posted at: 11/5/09 04:28 AM
You wanted something regexps don't do. Unless you use a long pattern of (\w*),(\w*),(\w*)
All times are Eastern Standard Time (GMT -5) | Current Time: 08:05 AM
<< Back