當前位置:首頁 » 編程語言 » java正則空格

java正則空格

發布時間: 2022-04-29 10:06:54

java中關於正則表達式中的空格匹配問題,看圖

因為讀入的input是「1」,不是「1 2」。
你可以在String input = new String(scan.next());這句下加一句System.out.println("input:" + input);試試。
你可以把「1 2」寫到一個文本文檔裡面然後讀出來,或者直接寫String a = 「1 2」;來匹配。

㈡ java中怎麼用正則表達式表示空格

public static void main(String[] args) {
// TODO 自動生成的方法存根
int i;
String s="I love you";
String index="\\s";
String str[]=s.split(index);
for(i=0;i<3;i++)
System.out.println(str[i]);
}
運行結果:
I
love
you

㈢ java 正則 字元串「只能」包含英文與空格

1.startswith(" ") or endswith(" ") return false;
2.public boolean hasTwinSpace(String name) {
String namee=new String(name);
String tem="";
boolean hasTwinSpace=false;
String[] namee2=namee.split("");
for(int i=0;i<namee2.length;i++) {
if(tem.matches("^[\\s]$") && tem.equals(namee2[i]) ) {
hasTwinSpace=true;
break;
}else {
tem=namee2[i];
}

}
//System.out.println("是否包含雙空格:"+hasTwinSpace);
return hasTwinSpace;
}
3."^[[A-Za-z]|\\s]+$" 用這個正則判斷是否只包含字母和空格
對正則不熟悉,我就只能這么幹了。。。如果有好的辦法,請回復我一下啊

㈣ 正則表達式 JAVA驗證字元串必須帶空格

importjava.util.regex.Matcher;
importjava.util.regex.Pattern;

publicclassTest{
publicstaticvoidmain(String[]args){
finalStringstr1="3dsga23";
Matchermatcher1=Pattern.compile("").matcher(str1);
if(matcher1.find()){
System.out.println("yes");
}else{
System.out.println("no");
}
}
}

㈤ java如何用正則去除<p>標簽後面的空格

java零寬斷言里的正則必須指定最大長度,我就寫了個100,匹配p標簽內可能含有的其他字元,應該夠用了

Stringp="<pid="test"class="para">今天我在圖書館加班。</p>";
p=p.replaceAll("(?<=<p.{0,100}>)[]+(?=\S)","");
System.out.println(p);

㈥ java正則表達式,怎麼匹配空白行

2樓的方法會把所有的換行符都刪除掉,剩下的整個文本全部都在一個行內,我想樓主應該是要保留正常的換行符的,也不符合LZ的本意。
復雜點的方法是把所有行都讀入一個List<String>里,然後對每一行,equals(Pattern.compile("\\s*\n")),返回true的刪除掉,剩下的行就是所需要的行了。

㈦ java正則表達式空格怎麼表示什麼

public static void main(String[] args) {
// TODO 自動生成的方法存根
int i;
String s="I love you";
String index="\\s";
String str[]=s.split(index);
for(i=0;i<3;i++)
System.out.println(str[i]);
}

㈧ java正則 匹配是否含有空格

/**
*包括空格判斷
*@paraminput
*@return
*/
(Stringinput){
returnPattern.compile("\s+").matcher(input).find();
}

㈨ java正則表達式怎樣匹配空格

s

㈩ java用正則表達式判斷空格的問題。

String eg="<p\s*=\s*>(\w*)<p\s*>";
Matcher m = Pattern.compile(eg, Pattern.CASE_INSENSITIVE).matcher(str);
while (m.find()) {
System.out.println(m.group(1));
}

m.group(int index)中的index指的是取第幾個捕獲型括弧中的值

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:595
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:889
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:583
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:766
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:687
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1015
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:258
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:117
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:808
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:715