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.

1
  • Could you escape the code with for space charaters and backticks (mycode), so it's easier to read? Commented Dec 13, 2009 at 22:18

1 Answer 1

4

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
)
Sign up to request clarification or add additional context in comments.

1 Comment

Remember to accept! You haven't accepted a single answer since you joined the site. (Click the green tick near the voting score.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.