public static Boolean includingnum (String str) throws exception{
Pattern p = pattern.compile ("[\u4e00-\u9fa5]*[\\d|\\w]+[\u4e00-\u9fa5]*");
or Pattern p = pattern.compile ("[\u4e00-\u9fa5]*[0-9|a-z| A-z]+[\u4e00-\u9fa5]* ");
Matcher M = P.matcher (str);
Boolean f =m.matches ();
return F;
}
Note: in Java Regular:
\\d represents non-numeric
\\d represents a number
\\w denotes non-word
\U4E00-\U9FA5 is the encoding range for Chinese characters
\\w means words
One of the \ is the escape character!!
[\d\d], [\w\w], [\s\s] These three represent no matter what character. public static void Main (string[] args) {String reg = "[\\d\\d]*\" [^\ "]*\" [\\d\\d]* ";String str = "Hello \" five "auxiliary"; Hello, "all five" auxiliaryBoolean f = str.matches (reg);System.out.println (f);str = "\" Five "" ";//" Five "F = str.matches (reg);System.out.println (f);}The results are true;\\s does not represent Chinese characters in Java, remember. Although it is possible to represent Chinese characters on a regular test machine
In Java, you infer whether the Chinese string contains English or a number