Search code examples
phppreg-match

How to preg_match if match found but if not then preg_match another sentence?


My $data contains "<File label=\"cat.{1,20}>(.*?)</File>" or "<File label=\"dog.{1,20}>(.*?)</File>" or "<File label=\"6969.{1,20}>(.*?)</File>" how to preg match any of those choices?

preg_match("'<File label=\"cat.{1,20}>(.*?)</File>'si", $data, $url); works only for cat. Sorry I am bad to tell what is the problem :D


Solution

  • preg_match("'<File label=\"(?:cat|dog|6969).{1,20}>(.*?)</File>'si", $data, $url); 
    

    this will match all of your $data :)