Convert HTML tag img in code to [IMG]URL[/IMG]JS code

Source: Internet
Author: User
Tags tag name
The code is as follows Copy Code

//ig

This regular and matching link tag is basically the same, modified as follows, Tag name IMG, no end tag but > end.

The test code is as follows:

The code is as follows Copy Code
<script type= "Text/javascript" >
function Replacereg (REG,STR) {
Return Str.replace (Reg, ' [img]$1[/img] ')
}
var reg =
//ig;
var str = ' I am the legendary picture of the Hey. ';
document.write (Replacereg (reg,str) + ' <br/> ');
</script>

The second is replacing the flash code embedded with the object code with [swf]url[/swf].

The positive text is as follows:

The code is as follows Copy Code
/<object[ss]*?src= ([ss]+?) (? =s) [ss]*</object>/i

If all of the attributes have double quotes, they also need to be modified.

The test is as follows:

The code is as follows Copy Code

 < Script type= "Text/javascript" >
 function replacereg (reg,str) {
  return str.replace (Reg, ' [swf]$1 [/swf] ')
 }
 var reg =/<object[ss]*?src= ([ss]+?) (? =s) [ss]*</object>/i;
 var str = ' <object classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000
codebase=http:// download.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=5,0,0,0 width=255 height=250>< param name=movie
Value=url><param name=quality value=high><embed src=url quality=high
Pluginspage =http://www.macromedia.com/shockwave/download/index.cgi?
P1_prod_version=shockwaveflash type=application/x-shockwave-flash
width=255 height=250></embed> </object> ';
 document.write (Replacereg (reg,str) + ' <br/> ');
 </script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.