Teach you how to replace all HTML tags when outputting text

Source: Internet
Author: User
Tags html tags regular expression
Only to the novice, the predecessors do not come to see me move the door to get axe. Hehe
Often see a novice to ask such a topic, in fact, on the regular expression I do not understand.
Yesterday afternoon looked at Microsoft's regular expression, a little understanding.
Today also write a function, only practice, the wrong person please advise.
Here is an example:
The original text is this: "<a href=" "" "><strong>test1</strong></a> <b>test2</b> <font color= Red>test3</font> test4 "
<script language= "VBScript" >
Function regexptest (PATRN, strng,rewho)
Dim Re,match,matches,retstr
Retstr=strng
Set Re = New RegExp
Re.pattern = patrn
Re.ignorecase = True
Re.global = True
Set matches = Re.execute (RETSTR)
For the Match in matches
Restr = restr & match.value& ","
Retstr=replace (retstr,match.value,rewho)
Next
Restr=replace (Restr, "<", "&lt;")
Restr=replace (Restr, ">", "&gt;")
Regexptest = "This is the original:" &strng& <br> This is replaced: "&ReStr&" <br> This is the rest: "&retstr
End Function
document.write regexptest ("(<[^{><}]*>)", "<a href=" "" "><strong>test1</strong></ a> <b>test2</b> <font color=red>test3</font> test4 "," ")
</Script>
[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]
The key is to <[^{><}]*> this regular expression, although very simple, but I still I understand the shallow, for you to say.
The HTML tag ends with a less than "<", with a greater than number ">".
So all the greater than the less than the number in this regular expression represents the HTML tag, not the special character.
"["] "the square bracket expression contains characters that match only the bracket expression in the regular expression
A single character in the position, I simply understand, it is a match to a position of the individual characters.
The "^" Mark is a special symbol, inside the brackets, followed by a list character, so it means
All characters that are not in the list or range. As I understand it, he's the equivalent of "not" in our program.
So the ^{>&lt in square brackets means that the word Fu Fei is greater than or not less than the number.
Inside the curly braces are removed in fact the same. Curly braces are also special characters

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.