常用正则表达式
(1)数字(整数或者小数)
String input = "324.456";
System.out.println(input.matches("\\d*\\.?\\d+"));
(2)查询[???]
在微博文本中,表情符号的文本表达方式为"[???]",其中的文字长度为1-3。
Pattern p = Pattern.compile("(\\[[^\\]]{1,3}\\])",
Pattern.CASE_INSENSITIVE + Pattern.MULTILINE);
String str = "小朋友100days[酷]432342[][花心]321321[哈哈][e4r32w32]";
Matcher m = p.matcher(str);
int index = 0;
while (m.find(index)) {
index = m.end();
System.out.println(m.group(1));
}

浙公网安备 33010602011771号