JS regular interception replaces a string between specific characters __js

Source: Internet
Author: User

	var html= "Ssssss @ username and Topic #话题标题 # with a different color high @ false Bright @ Username 2 and sss# This topic is wrong #ss";
	var html1= "Ssssss @ username and Topic #话题标题 # with a different color high @ false Bright @ Username 2 and sss# This topic is wrong #ss";
	var reg1=/(@[^]*)/g;
	var reg2=/(#[^#]*#)/g;
	var reg3=/(#[^#]*#)/g;
	document.write (HTML);
	document.write ("<br/>");
	Html=html.replace (REG1, "<span style= ' color:red ' >$1</span>");
	Html=html.replace (REG2, "<span style= ' Color:green;") >$1</span> ");
	document.write (HTML);
	document.write ("<br/>");
	HTML1 = Html1.replace (reg3, "<span style= ' Color:blue;") >$1</span> ");
	document.write (HTML1);
	document.write ("<br/>");
	var a = "20141021123212";
	var reg4 =/(\d{4}) (\d{2}) (\d{2}) (\d{2}) (\d{2}) (\d{2})/;
	A = A.replace (REG4, "$1-$2-$3 $4:$5:$6");
	document.write (a);
	document.write ("<br/>");
	var c = "Good Ah {topic title} with different colors sss{This topic good}ss";
	var reg5=/({[^{]*})/g;
	c = C.replace (Reg5, "<span style= ' color:red ' >$1</span>");
	document.write (c);
	document.write ("<br/>");


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.