过滤HTML标签的Java正则表达式 (?s)<.*?/?.*?>
按照你的要求编写的用正则表达式过滤HTML标签的Java程序如下
public class AA {
public String tagFilter(String s){
String regex = "(?s)<.*?/?.*?>"
String ss=s.replaceAll(regex,"")
return ss
}
public static void main(String[] args) {
String s="<div class=\"guid time online\">测试 abc</div><span data-url=\"games/details/\" class=\"guid done\">你好13548</span><a href=\"games/details/\" class=\"guid\">15个字母Abc</a><i class=\"icon-guid\"/>"
String result=new AA().tagFilter(s)
System.out.println(result)
}
}
如下:public static String do_post(String url, List<NameValuePair> name_value_pair) throws IOException {
String body = "{}"
DefaultHttpClient httpclient = new DefaultHttpClient()
try {
HttpPost httpost = new HttpPost(url)
httpost.setEntity(new UrlEncodedFormEntity(name_value_pair, StandardCharsets.UTF_8))
HttpResponse response = httpclient.execute(httpost)
HttpEntity entity = response.getEntity()
body = EntityUtils.toString(entity)
} finally {
httpclient.getConnectionManager().shutdown()
}
return body
}
public static String do_get(String url) throws ClientProtocolException, IOException {
String body = "{}"
DefaultHttpClient httpclient = new DefaultHttpClient()
try {
HttpGet httpget = new HttpGet(url)
HttpResponse response = httpclient.execute(httpget)
HttpEntity entity = response.getEntity()
body = EntityUtils.toString(entity)
} finally {
httpclient.getConnectionManager().shutdown()
}
return body
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)