请帮助我完成以下任务:
我的数组中有许多如下所示的文件:
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 中)。
最佳答案
这个想法,如果你有少量不同的结局:
if (filename.endsWith("0.txt")) a++;
关于java - Java中的正则表达式模式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838135/