導航:首頁 > 編程語言 > javaendswith正則

javaendswith正則

發布時間:2024-11-25 13:34:29

Ⅰ 求java大神幫忙,我現在有一個文件夾下有多個json格式的txt文本,如何讀取所有txt文本內容。

正則表達式,如果後綴為txt則讀取

Ⅱ JAVA中, 正則表達式匹配以 .png結尾該怎麼寫

.png前必需有字元:/^[\w-]+(\.png)$/
.png前不必需有字元:/^[\w-]*(\.png)$/

Ⅲ 正則表達式匹配文件類型

應該這樣寫:"^\S+\.doc$" 表示這樣的一個字元串:一個或一個以上的非空白字元開始加上以.doc結尾的字元串

Ⅳ java 怎麼輸入一串字元 以#號作為結束標識符

用正來則表源達式:
如:String s = "string#";
Pattern p = Pattern.compile("[\\w]*#$");
Matcher m = p.matcher(s);
System.out.println(m.matches());

Ⅳ 求java正則表達式,匹配pdf或者JPEG文件名。

摟著這個要看情況更具文件名特點來,
如果都是AD開頭,那麼:AD_.*?\.pdf
如果文件名沒有特點,但是在路徑中:[\\/].*?\.pdf
總之要弄懂原理靈活運用

Ⅵ java正則表達式截取字元串

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

publicclassHello{
publicstaticvoidmain(String[]args){
Stringre="\[([^\]]+)\]";
Stringstr="[您好],abcdefg,[abc]";

Patternp=Pattern.compile(re);
Matcherm=p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
}
}
}

將m.group(1)組建成你自己想內要的格式容就好了

Ⅶ 用正則表達式怎麼獲得*.txt所有的txt文件類型的文件名(java方面的,最好有具體的代碼),在此十分感謝!

就是.+.txt就行 .在正則表達式里是鍵盤輸入的任意符號(你可以理解為一個佔位符),+標識1到多個。 這個的意思是 1到多個鍵盤任意輸入字元.txt

Ⅷ 用java正則表達式提取java程序中的注釋

正則的效率非常低,有很多不用正則的好方法:
一,示例 某java程序
比如說一個Test2.java,將其保存在C盤根目錄下,代碼內容如下
/**
* @author xxx
*
*/
public class Test2 {
/* main method */
public static void main(String[] args) {
//a
int a =5;
//b
int b =5;
//a+b
System.out.println(a+b);

}
}

二,提取注釋程序,將所有注釋放到一個List裡面,最後列印輸出:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Test {
private static final String javaFilePath = "C:/Test2.java";
public static void main(String[] args) throws IOException {
List<String> comments = new ArrayList<String>();
BufferedReader bfr = new BufferedReader(new InputStreamReader(new FileInputStream(javaFilePath)));
String line=null;
while((line=bfr.readLine())!=null){
line = line.trim();
if(line.startsWith("//")){
comments.add(line);
}
else if(line.startsWith("/*")&&line.endsWith("*/")){
comments.add(line);
}else if(line.startsWith("/*")&&!line.endsWith("*/")){
StringBuffer multilineComment = new StringBuffer(line);
while((line=bfr.readLine())!=null){
line = line.trim();
multilineComment.append("\n").append(line);
if(line.endsWith("*/")){
comments.add(multilineComment.toString());
break;
}
}

}
}
bfr.close();
for(int i=0;i<comments.size();i++){
System.out.println("第"+(i+1)+"處注釋: ");
System.out.println(comments.get(i));
}
}

}

三,輸出結果:
第1處注釋:
/**
* @author xxx
*
*/
第2處注釋:
/* main method */
第3處注釋:
//a
第4處注釋:
//b
第5處注釋:
//a+b

閱讀全文

與javaendswith正則相關的資料

熱點內容
釘釘傳送文件最大多少兆 瀏覽:126
app下載哪裡最全 瀏覽:599
word如何畫大箭頭 瀏覽:245
word批量轉pdf工具21注冊機 瀏覽:546
列印文檔文件3000字需要多少錢 瀏覽:239
泊車助手app 瀏覽:147
pscs6完全自學教程 瀏覽:461
文件夾去不掉只讀屬性 瀏覽:203
qq怎麼接收文件夾 瀏覽:35
javahashmapvalues 瀏覽:548
滑鼠選定不了文件內容是壞了么 瀏覽:589
打開excel標准模板文件名 瀏覽:798
該文件名字不包含擴展名 瀏覽:565
華為備份文件 瀏覽:368
批量刪除cpp文件代碼注釋的工具 瀏覽:312
下列哪些不屬於可編程邏輯器件 瀏覽:963
蘋果6p跳屏是什麼原因 瀏覽:383
下載文件路徑是什麼 瀏覽:852
linux下o文件多重定義 瀏覽:135
為什麼在人多的地方沒有網路 瀏覽:170

友情鏈接