开发者

Java Reg-ex to validate file convention

How to check if the following is part of the file name using regular expressions

.en.
.fr.
.pt.
.de.
.ja.
.es开发者_运维技巧.
.it.
.cn.

I know one other way is to check the index of and return boolean.


Just do a match of \.(en|fr|pt|de|ja|es|it|cn|)\.


Just use the regex...

.*\.(?:en|fr|pt|de|ja|es|it|cn)\..*


Try this expression: \.(?:en|fr|pt|de|ja|es|it|cn)\. or for String#matches(): .*\.(?:en|fr|pt|de|ja|es|it|cn)\..* (note that in string literals, you need to escape the \\: ".*\\.(?:en|fr|pt|de|ja|es|it|cn)\\..*")


string.matches(".*\\.(en|fr|pt|de|ja|es|it|cn)\\..*");

or you can precompile the pattern with

Pattern p = Pattern.compile(".*\\.(en|fr|pt|de|ja|es|it|cn)\\..*");

and check with p.matches(string);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜