高手给一个正则表达式 匹配以下三种情况:[[Select Postion]]和这种[at the [Select postiont] int]还有[select] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String regex="(\\[at the \\[Select Postion\\] int\\])|(\\[select\\])|(\\[Select Postion\\])"; 我要匹配的是[[Select Postion]], [at the [Select postiont] int], [select ],这三种情况,中括号中的文字是可变得。谢谢!! String regex="(\\[.+\\[.+\\].+\\])|(\\[.+\\])|(\\[.+\\])"; String regex="(\\[.+\\[.+\\].+\\])|(\\[\\[.+\\]\\])|(\\[.+\\])"; 再改一下:String regex="(\\[[^\\[\\]]+\\[[^\\[\\]]+\\][^\\[\\]]+\\])|(\\[\\[[^\\[\\]]+\\]\\])|(\\[[^\\[\\]]+\\])";下面是测试:public class Test3{ public static void main(String[] args) { String regex="(\\[[^\\[\\]]+\\[[^\\[\\]]+\\][^\\[\\]]+\\])|(\\[\\[[^\\[\\]]+\\]\\])|(\\[[^\\[\\]]+\\])"; String[] strs={ "[123[444]344]", "[2345uwr]", "[[fjrrfg]]", "[fff]uuyyy", "[fjf[3333]]", "[sd[3ff]asdf]fsaf" }; for(String s:strs){ System.out.print(s); String isMatch=": 匹配"; if(!s.matches(regex)){ isMatch=": 不匹配"; } System.out.println(isMatch); } }}结果:F:\java>java Test3[123[444]344]: 匹配[2345uwr]: 匹配[[fjrrfg]]: 匹配[fff]uuyyy: 不匹配[fjf[3333]]: 不匹配[sd[3ff]asdf]fsaf: 不匹配 取字符串中所有子串的索引(100分) 怎么也解决不了,弹出式内容辅助菜单,希望帮忙 谁能帮帮我!!ArrayList! java中能否识别中文目录或读取中文命名的文件? 基于java-SWT的C/S结构(网络版)毕业设计问题讨论 面试题 关于包的问题 如何调用一个方法中的参数? where can i download WebSphere4.0 ? 怎么把一个jar包里的类交给spring管理并进行aop 急问GUI中jtextarea 中的鼠标事件(在线等。。。) char
[select
],这三种情况,中括号中的文字是可变得。谢谢!!
String regex="(\\[[^\\[\\]]+\\[[^\\[\\]]+\\][^\\[\\]]+\\])|(\\[\\[[^\\[\\]]+\\]\\])|(\\[[^\\[\\]]+\\])";
下面是测试:public class Test3{
public static void main(String[] args) {
String regex="(\\[[^\\[\\]]+\\[[^\\[\\]]+\\][^\\[\\]]+\\])|(\\[\\[[^\\[\\]]+\\]\\])|(\\[[^\\[\\]]+\\])";
String[] strs={
"[123[444]344]",
"[2345uwr]",
"[[fjrrfg]]",
"[fff]uuyyy",
"[fjf[3333]]",
"[sd[3ff]asdf]fsaf"
};
for(String s:strs){
System.out.print(s);
String isMatch=": 匹配";
if(!s.matches(regex)){
isMatch=": 不匹配";
}
System.out.println(isMatch);
}
}
}结果:
F:\java>java Test3
[123[444]344]: 匹配
[2345uwr]: 匹配
[[fjrrfg]]: 匹配
[fff]uuyyy: 不匹配
[fjf[3333]]: 不匹配
[sd[3ff]asdf]fsaf: 不匹配