字符串如下:
EF("","","","","","") 其中双引号中间可以输入内容也可以不输入,如下(前面两个字符不定):
例子:QM("4105","2008","01","[部门档案=03]","借")昨天的答复:
.{2}\(\".*\"\,\".*\"\,\".*\"\,\".*\"\,\".*\"\)
昨天有两位给了回复,但是不对,如果我上面的例子删一对引号内容后还可以匹配...继续求解.
EF("","","","","","") 其中双引号中间可以输入内容也可以不输入,如下(前面两个字符不定):
例子:QM("4105","2008","01","[部门档案=03]","借")昨天的答复:
.{2}\(\".*\"\,\".*\"\,\".*\"\,\".*\"\,\".*\"\)
昨天有两位给了回复,但是不对,如果我上面的例子删一对引号内容后还可以匹配...继续求解.
Pattern pat = Pattern.compile(".{2}\\((\\\".*\\\")*\\)");
Matcher mat = pat.matcher(str);
System.out.println(mat.find());
public static void main(String[] args){
String str = "dfsaQM(\"4105\",\"01\",\"[部门档案=03]\",\"借\")fasdQM(\"4105\",\"01\",\"[部门档案=03]\",\"借\")";
String regex = ".{2}\\((\\\".*\\\")*\\)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
System.out.println(m.find());
System.out.println(m.group());
}
}
输出的结果:true
QM("4105","01","[部门档案=03]","借")fasdQM("4105","01","[部门档案=03]","借")
String regex = ".{2}\\((\\\"[^\\\"]*\\\"[\\,\\)]+)*";
cyberpeng:
String reg = ".{2}\\(\"[^\"]*\"\\(\\,\"[^\"]*\"\\)*\\)";
Pattern p = Pattern.compile(reg);
String a = QM("4105","2008","01","[部门档案=03]","借") ;
boolean b = p.matcher(a).lookingAt();
返回b为false
至于lisl2003我感觉离我的概念有很大的差距....
谢谢!
String str = "QM(\"4105\",\"2008\",\"01\",\"[部门档案=03]\")";
String reg = ".{2}\\(\\\"[^\\\"]*\\\"(,\\\"[^\\\"]*\\\")*\\)";
Pattern pat = Pattern.compile(reg);
Matcher mat = pat.matcher(str);
System.out.println(mat.matches());
System.out.println(mat.group());
public class RegexString {
public static void main(String[] args){
String str = "dfsaQM(\"4105\")fasdQM(\"4105\",\"01\",\"[部门档案=03]\",\"借\")";
String regex = ".{2}\\((\\\"[^\\\"]*\\\"[\\,\\)]+)*";
System.out.println("测试字符串:"+str);
System.out.println("我给出的正则表达式:"+regex+"\n");
System.out.println("符合要求的字符串:");
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}
}
}运行结果:测试字符串:dfsaQM("4105")fasdQM("4105","01","[部门档案=03]","借")
我给出的正则表达式:.{2}\((\"[^\"]*\"[\,\)]+)*符合要求的字符串:
QM("4105")
QM("4105","01","[部门档案=03]","借")
我现在判断前面字符只能是QM或者QC或者FS或者JFS应该怎么用正则表达式呢,只能是
我给出的正则表达式:(QM|QC|FS|JFS)\((\"[^\"]*\"[\,\)]+)*
谢谢两位帮忙....
QM("4105","2008","01","[部门档案=03]","借") 是合法的,但
QM("4105",aa"2008","01","[部门档案=03]","借") 是不合法,上面的正则表达式可以通过.....
/^(QM|QC|FS|JFS)\((\"[^\"]*\"\,){5}(\"[^\"]*\"\))$/