Forum Topic: Search same pattern several times.

(143 views • 7 replies)

This topic is 1 page long.

<< < > >>
None

Loccie

Reply To Post Reply & Quote

Posted at: 11/4/09 10:25 AM

Loccie NEUTRAL LEVEL 16

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?


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/4/09 10:37 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,390

Boop

(\w*(,\w*)*)

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Loccie

Reply To Post Reply & Quote

Posted at: 11/4/09 10:55 AM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,059

This doesn't seem to work at all.


None

Craige

Reply To Post Reply & Quote

Posted at: 11/4/09 12:10 PM

Craige LIGHT LEVEL 08

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.


None

Loccie

Reply To Post Reply & Quote

Posted at: 11/4/09 12:42 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,059

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
)

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/4/09 01:27 PM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,390

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.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Loccie

Reply To Post Reply & Quote

Posted at: 11/4/09 03:57 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,059

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.


None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/5/09 04:28 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,390

You wanted something regexps don't do. Unless you use a long pattern of (\w*),(\w*),(\w*)

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


All times are Eastern Standard Time (GMT -5) | Current Time: 08:05 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!