1、新建java类;
2、编写java代码,匹配开头为'{'结尾为'},'的表达式;
3、编写测试字符串1'{abc}' 及2'{abc' ;
while (m2.find()) {
System.out.println(m2)
}
4、查看输出内容,可以看到字符串1'{abc}' 满足要求,而字符串2'{abc' 不满足要求;
模式串:"^\\p{Alpha}[\\p{Alnum},. ]{0,58}$"
或
"^[a-zA-Z][\\da-zA-Z,. ]{0,58}$"
都行。
String s = "abc >def<hig"String regex = ">.+?<"
Pattern p = Pattern.compile(regex)
Matcher m = p.matcher(s)
System.out.println(m.group())