* C:\ Temp \myfile_124.txt*の形式のファイルがあります
アンダースコアの後と拡張子の前にある数字「 124 」だけを与える正規表現が必要です。
私はいくつかの方法を試しましたが、最新のものは
(.+[0-9]{18,})(_[0-9]+)?\\.txt$
目的の出力が得られません。誰かが私に何が悪いのか教えてもらえますか?
Matcher matcher = FILE_NAME_PATTERN.matcher(filename);
if (matcher.matches() && matcher.groupCount() == 2) {
try {
String index = matcher.group(2);
if (index != null) {
return Integer.parseInt(index.substring(1));
}
}
catch (NumberFormatException e) {
}