tags:

views:

90

answers:

1

Hey Guys I Am Trying To Use One Regex Pattern If And Else

//$pattern    = "%http://depositfiles.com/[a-z]{2}/files/[0-9-a-z-A-z]*%";
//$pattern    = "%http://depositfiles.com/files/[0-9-a-z-A-z]{9}%";

i just want to use one regex pattern to match the depositfiles

$subject = 'http://depositfiles.com/files/9178jwt09 http://depositfiles.com/en/files/9178jzt09';
$pattern = '%http://depositfiles.com/files/[a-z]{2}(?=a-z]{2}/)then|(?![0-9-a-z-A-z]{9})else)%';

preg_match_all($pattern,$subject,$array);
print_r($array);

result if it works :

Array ( [0] => Array ( [0] => http://depositfiles.com/files/9178jzt09  [1]) =>  http://depositfiles.com/en/files/9178jzt09)

so i just need one regex pattern to define the 2 subjects thanks cheers.

+3  A: 

Would this work for you?

$subject = 'http://depositfiles.com/files/9178jwt09 http://depositfiles.com/en/files/9178jzt09';
$pattern = '_http://depositfiles.com/(?:[a-z]{2}/)?files/[0-9a-zA-Z]{9}_';
preg_match_all($pattern,$subject,$array);
print_r($array[0]);

Output:

Array
(
    [0] => http://depositfiles.com/files/9178jwt09
    [1] => http://depositfiles.com/en/files/9178jzt09
)
Mark Byers
thanks a million bro it WORKS!!
Saxtor
Remember to accept! You haven't accepted a single answer since you joined the site. (Click the green tick near the voting score.)
Mark Byers
Pls, accept the answer
Tomasz Struczyński