The regular expression is used to process image addresses and img tags. The regular expression is img.
You cannot upload an emoticon or image address directly.
Therefore, you must process the img tag before uploading a comment or image. For example, we hope to help more programmers ~
<Span style = "font-size: 14px; "> // The first step is to obtain the string var str = 'image 1 Image 2 Image 3 '; </span>
Process the obtained string
<Span style = "font-size: 14px; "> // Replace the img tag with the specific encoding expression var reg =/] * src [= \" \ '\ s] + [^ \.] * \/([^ \.] + )\. [^ \ "\ '] + [\" \']? [^>] *>/Gi; str = str. replace (reg, "[face: faces 1.gif]"); console. log (str); </span>
Calculation Result:
<Span style = "font-size: 14px;"> image 1 [face: sanai.gif] Image 2 [face: em_23.gif] Image 3 [face: 451.gif] </span>
In this way, the code uploaded to the server will not have html tags, which is a good way to deal with html tags with image comments and upload information prohibited.
Next:
The running result returned from the previous step on the server is parsed in reverse mode. The method is as follows:
<Span style = "font-size: 14px;"> // Replace the specified encoding method with the expression var regg =/face :( [\ WMG +).gif/gi; str = str. replace (regg, "
The running result is:
<Span style = "font-size: 14px; "> image 1 Image 2 Image 3 </span>
The following is an html page of the Code, which can be copied and pasted to an html file and run directly. It is available for test.
<Span style = "font-size: 14px;"> <! DOCTYPE html>
The above two methods can solve the positive and negative operations on the img tag. The first method is the previous collection, but you do not remember the original author. If there is any offense, you can propose a signature. The latter method is self-writing and has some limitations. You are welcome to discuss it ~
The above section describes how to use regular expressions to process image addresses and img tags. I hope this will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!