如何删除除img外的所有html标签?(How to remove all html tags except img?)
我收到了一些html文本,其中包含各种各样的html标签,例如
<table>, <a>, <img>
等。现在我想用正则表达式去除除
<img ...>
和</img>
(和大写<IMG></IMG>
)之外的所有html标记。这个怎么做?
更新:
我的任务非常简单,它只是在头版中打印html的文本内容(包括图像)作为摘要,所以我认为正则表达式很好,很简单。
再次更新
也许一个样本会让我的问题更好理解:)
有一些html文本:
<html> <head></head> <body> Hello, everyone. Here is my photo: <img src="xxx.jpg" />. And, <a href="xxx">know more</a> about me! </body> </html>
我想保留,并删除其他标签。 以下是我想要的:
Hello, everyone. Here is my photo: <img src="xxx.jpg" />. And, know more about me!
现在我编码如下:
html.replaceAll("<.*?>", "")
但它会删除
<
和>
之间的所有内容,但我想保留<img xxx>
和</img>
,并删除< and >
之间的其他内容谢谢大家!
I got some html text, which contains all kinds of html tags, such as
<table>, <a>, <img>
, and so on.Now I want to use a regular expression to remove all the html tags, except
<img ...>
and</img>
(and upper case<IMG></IMG>
).How to do this?
UPDATE:
My task is very simple, it just print the text content(including images) of a html as a summary in the front page, so I think regular expression is good and simple enough.
UPDATE AGAIN
Maybe a sample will make my question better to understand :)
There are some html text:
<html> <head></head> <body> Hello, everyone. Here is my photo: <img src="xxx.jpg" />. And, <a href="xxx">know more</a> about me! </body> </html>
I want to keep , and remove other tags. Following is what I want:
Hello, everyone. Here is my photo: <img src="xxx.jpg" />. And, know more about me!
Now I code like this:
html.replaceAll("<.*?>", "")
But it will remove all the content between
<
and>
, but I want to keep<img xxx>
and</img>
, and remove the other content between< and >
Thank for everyone!
原文:https://stackoverflow.com/questions/3297300
最满意答案
如果你纯粹看绘画的速度,你可以将图片分成许多较小的图片,这些图片会同时处理。 执行此操作的最有效方法是使用多个线程。
如果您需要更多信息,请评论。
If you're looking purely at speed of drawing, you could split the picture into a number of smaller pictures which are processed simultaneously. The most effective way of doing this would be using multiple threads.
Comment if you need more info.
相关问答
更多-
你不需要在execute方法中传递一个Thread。 相反,您需要传递一个Runnable对象,如下所示: ExecutorService tasker = Executors.newFixedThreadPool(20); for(double t = 0.0; t<=5.0; t = t + 0.50 ){ // t is time interval tasker.execute(new MyRunnable(t)); } .... .... class MyRunnable implement ...
-
最大的疑问是内联视图(或派生表,在MySQL版本中).MySQL将实现派生表,然后外部查询将针对它运行。 另一个嫌疑人是SELECT列表中的相关子查询。 这将由外部查询返回的每一行执行。 此外, ORDER BY app_created将需要Using filesort操作(除非您运行的是可能在派生表上构建索引的更新版本的MySQL。) 有一些奇怪的谓词,例如c.deleted = c.deleted 对于已deleted列中具有非NULL值的每一行,情况都是如此。 这相当于c.deleted IS NOT ...
-
由于nPr有一个明确的公式nPr(n, m) = n!/((nm)!)你一定要尝试使用它。 我的提示是: 记住那个! = n *(n-1)* ... * 2 * 1 请注意, while循环 (是的,循环,而非递归^^)可以极大地优化计算(除法取消了很多因子,让你得到乘法nPr(n, m) = n*(n-1)*...*(n-m+2)*(n-m+1) ) 最后,您应该在计算nPr(n,m) 后计算模数,以避免冗余模运算。 如果它有帮助,你可以尝试制定一个循环不变量 ,这几乎是一个声明,对于n和m所有有效值都应 ...
-
查看HayStack的大型应用程序,上传到文件系统然后存储到数据库就足以满足数百万的小型应用程序。 但是,像flickr这样的大公司使用干草堆对象。 Look into HayStack for large applications, uploading into a file system then storing into a DB would be sufficient for smaller applications even up to millions. However, larger comp ...
-
Javascript + HTML:如何有效地显示大量图像?(Javascript + HTML: How can I efficiently display a large list of images?)[2023-06-27]
显然,在一个视图中,数千个图像不会一次全部显示,但正如您所描述的那样,在一个长列表中。 我将采取的方法是缓冲图像并在滚动时显示它们。 这将要求您计算可以连续存储的图像数量,并且在当前滚动位置的前后至少缓冲两行或三行。 这种方法的唯一缺点是,在缩略图行很大的情况下获得平滑的滚动解决方案可能会很棘手。 Obviously the thousands of images are not going to be all displayed at once in a single view but as you de ... -
如果你纯粹看绘画的速度,你可以将图片分成许多较小的图片,这些图片会同时处理。 执行此操作的最有效方法是使用多个线程。 如果您需要更多信息,请评论。 If you're looking purely at speed of drawing, you could split the picture into a number of smaller pictures which are processed simultaneously. The most effective way of doing this w ...
-
每15分钟有效地查询一个巨大的时间序列表(Efficiently querying a huge time series table for one row every 15 minutes)[2022-03-11]
间隔15分钟: with i as ( select cf.tagindex, min(dateandtime) dateandtime from contfloattable cf group by floor(extract(epoch from dateandtime) / 60 / 15), cf.tagindex ) select cf.dateandtime, cf."Val", cf.status, t.tagname from ... -
如何有效地存储非常大的图形空间但是有快速索引?(How to Store Very Large Graphs Space Efficiently Yet have Fast Indexing?)[2023-06-07]
您可以将每个节点的边缘列表存储在单个阵列中。 如果每个节点的边数是可变的,则可以使用空边终止列表。 这将避免许多小列表(或类似数据结构)的空间开销。 结果可能如下所示: enum { MAX_NODES = 875713, MAX_EDGES = 5105039, }; int nodes[MAX_NODES+1]; // contains index into array edges[]. // index ... -
你有几个资源浪费在这里。 您正在检索的JSON文件比您需要的次数多24倍。 将调用移到内部循环中的file_get_contents() 。 准备好的陈述应该与这个念头一起使用:准备一次,执行很多次。 将语句准备移到任何循环之外,然后在循环内部执行它。 你没有建立一个适当的预备陈述。 该语句应该包含占位符( ?或:label格式),但是您要将值插入到您的中。 您传递给execute()所有参数都将被忽略。 编辑:实际上,你在页面上插入每一个值24次,即你为11页中的每一页插入24 * 24行。 建议更改摘要 ...
-
如果你想尝试不同的压缩,你可以从RLE开始,它适合你的数据 - http://en.wikipedia.org/wiki/Run-length_encoding - 即使在最简单的实现中,它也会非常快速。 相关的http://en.wikipedia.org/wiki/Category:Lossless_compression_algorithms包含更多的链接,如果你想自己推出或找到某人的实现,可以从其他算法开始。 随机评论:“......很多速度损失可能......”不是解决性能问题的方法。 测量并查看 ...