File Format # [filename].[2 letter locale].[outputformat - html/subject/text].xml
Valid filenames -
myname.en.html.xml
myname2.pt.subject.xml etc.
Also, filenames are coming from a column in the database.
Can somebody help me with the regex?
Thank You!
Edit# as per @drf
public static boolean isValidFileName( String fileName ) {
String expression = "^\\w+\\.[A-Z]{2}\\.(?>html|subject|text)\\.xml$" ;
CharSequen开发者_JS百科ce inputStr = expression ;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
return matcher.matches();
}
public static void main(String[] args) {
String fileName = "somefile.en.html.xml" ;
System.out.println("Is valid file name # " + fileName + " - " + isValidSEASFileName(fileName) ) ;
}
If a conservative file name validation is acceptable (letters and numbers only, no maximum length) and the two-letter locale can be any two letters, then something like this (set to case-insensitive) could work:
^\w+\.[A-Z]{2}\.(?>html|subject|text)\.xml$
Try the following:
[^\.]*\.[a-z]{2}\.(html|subject|text)\.xml
精彩评论