HTML搜索和更换服务器端 [英] html search and replace on server side

查看:139
本文介绍了HTML搜索和更换服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢搜寻堆栈<sometag>溢出< /sometag>
并替换为堆栈<sometag>下溢< /sometag>

它是一个大型HTML文本的一部分,我喜欢用Java来完成它(我可以使用服务器端技术有一些限制)。我搜索了一下,发现这个帖子:
如何在保留html标签/结构的情况下在html中查找/替换文本



其中一个答案表明用特殊标记标记,文本,然后使用正则表达式。最后取消标记并将字符串恢复为html。但它假设字符串出现在文本中的给定位置。我无法知道字符串的位置以及可能重复的次数。



当然,直接使用正则表达式搜索和替换并不适合,因为我需要保留html标签。



在此先感谢!

解决方案

看看 http://jsoup.org/ ,它可以处理各种标签。

I like to search something like stack <"sometag"> overflow</"sometag"> and replace with stack <"sometag">underflow</"sometag">

It is part of a large html text and I like to do it in Java (there is some limitation on the server side technologies that I can use). I searched through and found this post: How to find/replace text in html while preserving html tags/structure

One of the answers there suggests marking with special markers, producing plain text and then using regex. Finally unmarking and getting back the string to html. But it assumes that the string comes at a given position in the text. I have no way of knowing where the strings will be and how many times it may repeat.

Of course direct usage of regular expression search and replace is not appropriate here since I need to preserve the html tags.

Thanks in advance!

解决方案

Take look on http://jsoup.org/ It does all kinds of stuff with tags.

这篇关于HTML搜索和更换服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆