0

Possible Duplicate:
parse youtube video id using preg_match

I'd like to extract the youtube video id from an input string via regular expressions. The input is always as follows: [youtube=-J_JLXuioEI] and I need the id, which is -J_JLXuioEI in this case. Now I use the following regular expression:

preg_match_all('/youtube=([a-zA-Z0-9\-_]+)/', $string, $m );

I fear that Google uses other characters like ! in their ids and so I would like to ask if you have a general id how to parse these ids.

Thanks much in advance,

enne

Community
  • 1
  • 1
enne87
  • 2,221
  • 8
  • 32
  • 61
  • It's not the same. AFAIK he's asking to extract the ID from a string, not from Youtube URL. – m0skit0 Oct 25 '11 at 11:24
  • Sorry, I forgot to mention that I can input several such Strings, e.g "[youtube=-J_JLXuioEI] [youtube=-ABCD-EFG] [youtube=-J_JLXuioEV].." – enne87 Oct 25 '11 at 11:31

1 Answers1

0

Just get everything after = and before ]. Like

/\[youtube=(.+)\]/
m0skit0
  • 25,268
  • 11
  • 79
  • 127
  • Thanks m0skit0 but I forgot to mention that I can input several such strings like "[youtube=-J_JLXuioEI] [youtube=-ABCD-EFG] [youtube=-J_JLXuioEV].." and this one just works for one. – enne87 Oct 25 '11 at 11:33
  • Split them then parse one by one. – m0skit0 Oct 25 '11 at 12:44