[英]Java How to select half part of string?
I have string like this: 我有这样的字符串:
<html>
<body>
<p>Hello</p>
</body>
</html>
and In java I want to after selection string looked like this: 在java中,我希望选择字符串如下所示:
<p>Hello</p>
How? 怎么样?
This one line should do it: 这一行应该做到这一点:
String text = input.replaceAll("(?s).*(<p>.*</p>).*", "$1");
Or to just get everything in the <body>
tag, do this: 或仅将所有内容保存在<body>
标记中,请执行以下操作:
String text = input.replaceAll("(?s).*<body>(.*)</body>.*", "$1");
您可以使用JSoup ,它将对您很方便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.