Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列内の特定の位置にある文字を抽出する関数を見つけようとしています。たとえば、日付が含まれる長いファイル名があり、最終的に日付だけで終わらせたいとします。
'LT50420331984221PAC00_B7.tif'
「1984221」の部分だけが必要です。複雑な関数を思いつきましたが、もっと洗練された解決策があるかどうか疑問に思っていました。
文字列内の日付の正確な位置がわかっている場合は、使用できます
substr('LT50420331984221PAC00_B7.tif', 10, 16)
例えば:
gsub('(.*)([0-9]+{7})[A-Z].*','\\2','LT50420331984221PAC00_B7.tif') "1984221"
ここでは、日付が大文字の前の 7 桁であると想定しています。