String aa = "111 222 333 444 123 1234";
现在匹配 以1开头空格结尾的字符,结果是:111 123
String regEx1 = "(1.*? )";
Pattern pattern1 = Pattern.compile(regEx1);
Matcher matcher1 = pattern1.matcher(aa);
while(matcher1.find()){
System.out.println(matcher1.group());
}
我想匹配 不是1开头空格结尾的字符,结果是:222 333 444 1234
这组正则该怎么写?谢谢大家,在线等。java正则
现在匹配 以1开头空格结尾的字符,结果是:111 123
String regEx1 = "(1.*? )";
Pattern pattern1 = Pattern.compile(regEx1);
Matcher matcher1 = pattern1.matcher(aa);
while(matcher1.find()){
System.out.println(matcher1.group());
}
我想匹配 不是1开头空格结尾的字符,结果是:222 333 444 1234
这组正则该怎么写?谢谢大家,在线等。java正则
这个不用正则可能更简单吧,string.charAt(0)!=1和string.charAt()!=''
这个不用正则可能更简单吧
string.charAt(0)!=1和string.charAt(string.length()-1)!=''就行了
试试这个
\\b代表词边界
[02-9]除1以外所有的数字打头
后面[0-9]随意
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());
}
}