Search code examples
phpformattingpreg-match

How should I preg_match in correct format?


I have preg_match problem. I should preg_match if xml text is something like this below.

<File label="asd 480p" type="lol" rate="1500" resolution="854x480">ValueIwant</File>

or this

<File label="720p" default="1">ValueIwant</File>

Now I'm using format like that

preg_match("'<File label=\"(?:720|576|cat|asd 480p).{1,50}>(.*?)</File>'si", $streamdata, $streamurl);

But it's working only for values like on my second example code < File label="720p" default="1">


Solution

  • preg_match("'<File label=\"[(720)(576)(cat)(asd 480)].+>(.*)<\/File>'si", $streamdata, $streamurl);
    

    The regex you posted should work too if you replace the {1,50} with either a higher number than 50 or just a plus sign (+).