81,092
社区成员
发帖
与我相关
我的任务
分享
String regEx1 = "(1.*? )";
Pattern pattern1 = Pattern.compile(regEx1);
Matcher matcher1 = pattern1.matcher(aa);
while(matcher1.find()){
System.out.println(matcher1.group());
}
public static void main(String[] args) throws Exception {
String aa = "111 222 333 444 123 1234";
Matcher m = Pattern.compile("1[^\\s]*?(\\s|$)").matcher(aa);
//现在匹配 以1开头空格结尾的字符,结果是:111 123
while(m.find()){
System.out.println(m.group());
}
}
这个不用正则可能更简单吧
string.charAt(0)!=1和string.charAt(string.length()-1)!=''就行了
这个不用正则可能更简单吧,string.charAt(0)!=1和string.charAt()!=''