...

View Full Version : Resolved multiple pregmatch



cosmicsea
03-17-2010, 11:52 PM
hi im trying to do a pregmatch and have it run through multiple values and need some help.
I tried this right here.

preg_match('/p([\d][\d]?)/'|'/r\.([\d][\d]?)/'|'/z\.([\d][\d]?)/',$t,$m);

and this, and it doesnt work.

preg_match('/p([\d][\d]?)/','/r\.([\d][\d]?)/','/z\.([\d][\d]?)/',$t,$m);

do you see and understand what im trying to do? can someone help?

MattF
03-18-2010, 12:45 AM
Post an example of what you're trying to match.

cosmicsea
03-18-2010, 12:54 AM
Post an example of what you're trying to match.

well this is for a crawler script and im trying to make it loop through multiple values instead of "original code"
preg_match('/p([\d][\d]?)/',$t,$m);

I want to know if i can add more to the preg_match so that it only loops through 1 time instead of several instances of preg_match.

what that code is trying to match is the letter p and any random 2 numbers. for example "p12" and it works fine, i just want to add a couple more things for it to match like
'/r\.([\d][\d]?)/' which would be "r.12" or whatever. so in one loop i want it to check for multiple things instead of just "p12". does that tell you what you need? if not this may help, here is the whole function
function p_search($t)
{
preg_match('/p([\d][\d]?)/',$t,$m);
if (isset($m[1]))
{
return (int)$m[1];
} else {
return 0;
}
}

MattF
03-18-2010, 12:58 AM
Untested, and may also match a dot after a p, but try:



preg_match_all('#[prz]\.?(\d{2})#', $t, $m);


To match the p without a dot but the z or r with/without one:



preg_match_all('#(?:p|[rz]\.?)(\d{2})#', $t, $m);

cosmicsea
03-18-2010, 01:08 AM
Untested, and may also match a dot after a p, but try:



preg_match_all('/[prz]\.?(\d{2})/', $t, $m);


that seems to work thanks.:thumbsup: for future reference in case i decide to change "p", "r.", "z." to names such as "pat", "rob", and "zak" how would i go about doing that?

MattF
03-18-2010, 01:12 AM
preg_match_all('#(?:pat|rob|zak)(\d{2})#', $t, $m);

cosmicsea
03-18-2010, 01:16 AM
preg_match_all('#(?:pat|rob|zak)(\d{2})#', $t, $m);


Thanks alot matt!:thumbsup:
I appreciate the help you have gave to me multiple times now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum