Hi,
I have 2 regex with me which help me in embedding youtube video.
The 1st regex attaches
[video] ... [/video] BBcode around youtube URL
and 2nd regex does the actual embedding of youtube code.
I'm looking for one regex which does both of these.
#add video tag to video urls inserted without video tag
$text =~ s#(^|\s|\>)((http|https)://www.youtube.com/watch\?\.*v=([a-z0
+-9-_%]+)[&\w;=\+\-]*)#$1\[video\]$2\[\/video\]#isg;
#Embed respective video code
$text =~ s#\[video\](http|https)://www.youtube.com/watch\?\.*v
+=([a-z0-9-_%]+)[&\w;=\+\-]*\[\/video\]#<object class="restrain" type=
+"application\/x-shockwave-flash" width="640" height="385" data="http:
+\/\/www\.youtube\.com\/v\/$2"><param name="movie" value="http://www.y
+outube.com/v/$2"/><param name="wmode"
value="transparent"/><embed width="640" height="385" type="app
+lication/x-shockwave-flash" src="http://www.youtube.com/v/$2" /></obj
+ect>#isg;
The sample text may contain video with/without video BB code, so I need to satisfy both conditions and embed in both the cases. Eg:
$text= " Video1: http://www.youtube.com/watch?v=dTi4v3HveqE Video2: [video]http://www.youtube.com/watch?v=dTi4v3HveqE[/video]";
Any help on how to merge the 2 regex ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.