国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - Regular expression to replace img image tag with text [image]?
某草草
某草草 2017-05-19 10:26:58
0
4
893

Original content:

<p class="demo1">
    11
    <img src="images/IconfollowQuestion2.png" alt="" >
    22
    <img src="images/banner.png" style="width:250px;">
    33
</p>

The result to be obtained

11[圖片]22[圖片]33

How to write such a regular expression using js?

某草草
某草草

reply all(4)
大家講道理

string.replace(/<img(.*?)>/g, "[image]")

I just wrote one randomly, I don’t know if it’s right or not

Added a ? to change the regular expression into lazy mode, which will match as little as possible and only match one img at a time.

If ? is not added, it is greedy mode, which will match as many as possible and directly match all img.

給我你的懷抱
str.replace(/<img[^>]*>/g, "[圖片]"); 
滿天的星座
string.replace(/<img.*?>/g,'[圖片]')

Pay attention to two points: (1)*? 為非貪婪模式。(2) g Global matching.

某草草
str.replace(/<img[^>]*>/g, "[圖片]");
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template