簡體   English   中英

如何從名稱包含日期的 .txt 文件中提取日期? (斯卡拉)

[英]How can I extract date from a .txt file which name contains date? (Scala)

我有一個 .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$

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM