我有一个.txt文件作为我的光束编程项目的输入,使用scala spotify scio。
input= args.getOrElse("input", "/home/user/Downloads/trade-20181001.txt")
如何从文件名中提取日期2018 - 10 - 01(10月1日)?谢谢!
在上面的例子中,我只想使用下面的正则表达式。它搜索以8个数字结尾的任何内容,后跟.txt。
(?<dateTime>\d{8})\.txt$
(?<dateTime> is the start of a named capture group.
\d{8} means exactly 8 digits.
) is the end of the named capture group.
\. means match the character . literally.
txt means match txt literally.
$ means that the string ends there and nothing comes after it.
如果您不能在程序中使用命名捕获组,则可以在不使用它的情况下使用下面的正则表达式,并将其替换为.txt。
\d{8}\.txt$