This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。
7年前关闭。
请在完成以下操作时需要我的帮助:
我在数组中有许多类似以下的文件:
我想编写一个程序来执行以下操作:
所需的核心帮助是使用正则表达式(在Java中)。
7年前关闭。
请在完成以下操作时需要我的帮助:
我在数组中有许多类似以下的文件:
jack+0.txt
jack+2.txt
jack+4.txt
tim+0.txt
tim+2.txt
tim+4.txt
raph+0.txt
raph+2.txt
raph+4.txt
wells+0.txt
wells+2.txt
wells+4.txt
etc.
我想编写一个程序来执行以下操作:
if the filename is like *0.txt, a++;
if the filename is like *2.txt, b++;
if the filename is like *4.txt, c++;
所需的核心帮助是使用正则表达式(在Java中)。
最佳答案
for (File file : files) {
if (file.getName().matches(".*0[.]txt") {
a++;
} else if ...
}
关于java - Java中的正则表达式模式匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12838135/