- 匹配HTML标签
String regex = "(\\</{0,1}[A-Za-z]{1,10}\\s*[^>]*\\>)";
实例:
String content = "boys<h1>girls</h1>hello<table style='color=red'>world</table>"; String regex = "(\\</{0,1}[A-Za-z]{1,10}\\s*[^>]*\\>)"; Pattern patten = Pattern.compile(regex);// 编译正则表达式 Matcher matcher = patten.matcher(content);// 指定要匹配的字符串 while (matcher.find()) { // 此处find()每次被调用后,会偏移到下一个匹配 System.out.println(matcher.group()); }
- 匹配中文
String regex = "[\u4e00-\u9fa5]{1}[[\u4e00-\u9fa5]|,|。|, |.|;|;|?|?|!|!|[A-Za-z]|[0-9]]{0,}";
实例:
String content = "奰罍躄罍颣薐豳彝翳薹鬰鬰鬰鬰鬰鬰鬰(郁)1、应(ying)、奰(dubi)、躄(bi)、罍(zhilei)、颣(lei)、薐(daoleng)、豳(bin)、懿(yi)、彝(yi)、翳(yi)、薹(tai)、虩(x90i)、舄(xi)、衚(hu)、衕(tong)、觳(hu)、觫(su)、燹(xian)、盫(an)、媕(an)、娿(e)、寯(jun)、嬲(niao)、鳏(guan)、魑(chi)、魅(mei)、魍(wang)、魉(liang)、璺(wen)、齆(weng)、韛(bai)、櫼(jian)、谶(chen)、橐(tuo)、鼍(tuo)、聱(ao)。"; String regex = "[\u4e00-\u9fa5]{1}[[\u4e00-\u9fa5]|,|。|, |.|;|;|?|?|!|!|[A-Za-z]|[0-9]]{0,}"; Pattern patten = Pattern.compile(regex);// 编译正则表达式 Matcher matcher = patten.matcher(content);// 指定要匹配的字符串 while (matcher.find()) { // 此处find()每次被调用后,会偏移到下一个匹配 System.out.println(matcher.group()); }