tags:

views:

161

answers:

2
$content = preg_match('/[flv[^/]]+:(.*?)[^/]]*/]','', $content);

Could someone give me the regular expression for extracting [flv:example.flv 465 301] from a string. Also, I would like to put the example.flv into second element of the array, and the dimensions in to the third element. I have tried the above regex and it fails miserably. Any help would be much appreciated. Thanks

+3  A: 

You need to escape the literal square brackets or else they'll be treated as a character class. Also, I'm not sure what you're doing with all the [^/] as your example doesn't contain a /.

/\[flv:(.*?) (\d+ \d+)\]/

or to separate out the dimensions:

/\[flv:(.*?) (\d+) (\d+)\]/
Greg
Thanks man! Regex mystifies me so I was following one i knew worked and it evidently failed me. :D
Drew
+1  A: 

When I got this right you have 4 parts in your string:

  • 'flv:'
  • file name => [^\h]+
  • integer => [0-9]+
  • integer => [0-9]+

This would assemble to something like

'/flv:[^\h]+\h+[0-9]+\h+[0-9]+/'

Then you need to wrap these things into parantheses and you're done:

preg_match('/flv:([^\h]+)\h+([0-9]+)\h+([0-9]+)/', $string, $matches);
$file = $matches[1];
$width = $matches[2];
$height = $matches[3];
soulmerge