導航:首頁 > 編程語言 > java正則表達式驗證是否包含

java正則表達式驗證是否包含

發布時間:2024-03-27 03:35:49

java正則表達式如何判斷字元串中是否含有特殊字元

public class Test2 {
public static void main(String[] args){
String s = "123asdqwe__123 rew-trafgds";
if(s.replaceAll("[a-z]*[A-Z]*\\d*-*_*\\s*", "").length()==0)
System.out.println("input correct");
else
System.out.println("input incorrect");
}
}

② java 怎麼判斷一個字元串中是否包含數字

網路上已復經方製法了,參考如下:
1.用java自帶的函數
public
static
boolean
isnumeric(string
str){
for
(int
i
=
0;
i
<
str.length();
i++){
system.out.println(str.charat(i));
if
(!character.isdigit(str.charat(i))){
return
false;
}
}
return
true;
}

③ java正則表達式判斷一個字元前是否有一個字元

java使用match和pattern來實現判斷字元串是否不含有某個字元,實例如下:
/**
* 判斷字元串是否數值
* @param str
* @return true:是數值 ;false:不是數值
* @author:WD_SUHUAFU
*/
private boolean isNumber(String str)
{
Pattern pattern = Pattern.compile("^[0-9]+(.[0-9]*)?$");
Matcher match=pattern.matcher(str);
return match.matches();
}

④ Java 判斷字元串是否含有所有特殊符號

String ss = "Axs123a";
boolean a = ss.matches("[A-Za-z0-9\\u4e00-\\u9fa5]+");
System.out.println(a);
正則表達式:
中文、英文、數字但不包括下劃線等符號:^[\u4E00-\u9FA5A-Za-z0-9]+$
\u4E00-\u9FA5 匹配所有漢字
A-Za-z0-9 匹配 帶小寫字母和數字
+ 表示至少匹配一次,可以匹配無數次,空字元串默認返回false
^ 正則表達式開始符 $ 正則表達式結束符

⑤ java中如何用正則表達式判斷一個字元串中是否包含0-9的數字

// 判斷一個字元串是否都為數字
public boolean isDigit(String strNum) {
return strNum.matches("[0-9]{1,}");
}

// 判斷一個字元串是否都為數字
public boolean isDigit(String strNum) {
Pattern pattern = Pattern.compile("[0-9]{1,}");
Matcher matcher = pattern.matcher((CharSequence) strNum);
return matcher.matches();
}

//截取數字
public String getNumbers(String content) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}

// 截取非數字
public String splitNotNumber(String content) {
Pattern pattern = Pattern.compile("\\D+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 判斷一個字元串是否含有數字
public boolean hasDigit(String content) {
boolean flag = false;
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(content);
if (m.matches())
flag = true;
return flag;
}

閱讀全文

與java正則表達式驗證是否包含相關的資料

熱點內容
模組設定在哪個文件夾 瀏覽:162
蘋果現在怎麼看片 瀏覽:527
有什麼網站都是看大型聖誕樹 瀏覽:343
linux文件夾添加用戶許可權 瀏覽:231
word插入換行符 瀏覽:779
lol游戲在哪個文件夾 瀏覽:661
如何在整個excel文件夾內查找 瀏覽:342
贊麗app的步數怎麼兌換 瀏覽:862
蘋果手機文件夾透明 瀏覽:542
平板小米2刷win10刷機包下載 瀏覽:934
編程失誤會發生什麼 瀏覽:100
感嘆號在編程里是什麼意思 瀏覽:806
10歲孩子編程是學什麼的 瀏覽:484
咸魚進貨app有哪些 瀏覽:246
微購app什麼時候上線 瀏覽:243
psd文件平板要裝什麼軟體才能預覽 瀏覽:85
cad備份文件在哪找 瀏覽:678
word改變不了字體 瀏覽:293
刀鋒無雙裝備升級攻略 瀏覽:444
涼車讀數據流水溫應該是多少 瀏覽:785

友情鏈接