匹配特定数字:
^[1-9]\d*$ //匹配正整数
^-[1-9]\d*$ //匹配负整数
^-?[1-9]\d*$ //匹配整数
^[1-9]\d*|0$ //匹配非负整数(正整数 + 0)
^-[1-9]\d*|0$ //匹配非正整数(负整数 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮点数
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配负浮点数
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮点数(负浮点数 + 0)
^[1-9]\d*$ //匹配正整数
^-[1-9]\d*$ //匹配负整数
^-?[1-9]\d*$ //匹配整数
^[1-9]\d*|0$ //匹配非负整数(正整数 + 0)
^-[1-9]\d*|0$ //匹配非正整数(负整数 + 0)
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$ //匹配正浮点数
^-([1-9]\d*\.\d*|0\.\d*[1-9]\d*)$ //匹配负浮点数
^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$ //匹配浮点数
^[1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0$ //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]\d*\.\d*|0\.\d*[1-9]\d*))|0?\.0+|0$ //匹配非正浮点数(负浮点数 + 0)
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test2 { /**
* @param args
*/
public static void main(String[] args) {
String str = "111111111";
Pattern pattern = Pattern.compile("([0-3]|[5-9])*4([0-3]|[5-9])*");
Matcher matcher = pattern.matcher(str);
// while (matcher.find()) {
// System.out.println(matcher.group());
// }
if(matcher.find()){
System.out.println("有4");
}else{
System.out.println("无4");
} }}
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test2 { /**
* @param args
*/
public static void main(String[] args) {
String str = "1134113111";
Pattern pattern = Pattern.compile("[\\d&&[^4]]+");
Matcher matcher = pattern.matcher(str);
if(matcher.matches()){
System.out.println("没有4");
}
else{
System.out.println("有4");
}
}}
这样才对
import java.util.regex.Pattern;public class Test2 { /**
* @param args
*/
public static void main(String[] args) {
String str = "111111111";
Pattern pattern = Pattern.compile("4");
Matcher matcher = pattern.matcher(str);
if(matcher.find()){
System.out.println("有4");
}else{
System.out.println("无4");
} }}相信我,我的这个就行了
我测试过了
Pattern pattern = Pattern.compile("4");