【正则表达式】以 lbl_ 开头,以 } 或 | 符号结尾的字符串,用正则表达式怎么写?
【正则表达式】以lbl_开头,以}或|符号结尾的字符串,用正则表达式怎么写?程序语言是JAVA...
【正则表达式】以 lbl_ 开头,以 } 或 | 符号结尾的字符串,用正则表达式怎么写?程序语言是JAVA
展开
1个回答
展开全部
这个是正则匹配: ^lbl\_.*(\}|\|)$
java程序如下:
public class hello {
/**
* @param args
*/
public static void main(String[] args) {
String a="lbl_dddddddddddd }";
String b="lbl_dddddddddddddddd|";
String c=" d";
String regEx ="^lbl_.*(}||)$";
Pattern pattern = Pattern.compile(regEx);
Matcher matchera = pattern.matcher(a);
Matcher matcherb = pattern.matcher(b);
Matcher matcherc = pattern.matcher(c);
boolean rsa = matchera.matches();
boolean rsb = matcherb.matches();
boolean rsc = matcherc.matches();
System.out.println(rsa);
System.out.println(rsb);
System.out.println(rsc);
}}
result:
true
true
false
java程序如下:
public class hello {
/**
* @param args
*/
public static void main(String[] args) {
String a="lbl_dddddddddddd }";
String b="lbl_dddddddddddddddd|";
String c=" d";
String regEx ="^lbl_.*(}||)$";
Pattern pattern = Pattern.compile(regEx);
Matcher matchera = pattern.matcher(a);
Matcher matcherb = pattern.matcher(b);
Matcher matcherc = pattern.matcher(c);
boolean rsa = matchera.matches();
boolean rsb = matcherb.matches();
boolean rsc = matcherc.matches();
System.out.println(rsa);
System.out.println(rsb);
System.out.println(rsc);
}}
result:
true
true
false
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询