簡體   English   中英

如何只檢索沒有貪婪擴展名的文件名

[英]How to retrieve only filename without greedy extension

我想從

markets-map.es6.js
filename.abc.es6.js
filename.ab.def.es6.js
abc.js
defghi.es6.js
location-map.js
demographics-map.es7.js
demographics-map.tar.bz
demographics-map.tar.zip
demographics-map.tar.ball

以下內容:使用Regex的markets-mapfilename.abcfilename.ab.deffilename.abcabcdefghilocation-mapdemographics-mapdemographics-map 你能幫我嗎?

您的問題是特定的,因此您有一種解決方法,這是逐案解決的,您可以使用以下正則表達式:

(.*?)(((\.es\d+)?\.js)|(\.tar\.(bz|zip|ball)))

因此,您只能參加第一個小組的正則表達式演示:

演示正則表達式


Input                         Output

markets-map.es6.js        ->  markets-map
filename.abc.es6.js       ->  filename.abc
filename.ab.def.es6.js    ->  filename.ab.def
abc.js                    ->  abc
defghi.es6.js             ->  defghi
location-map.js           ->  location-map
demographics-map.es7.js   ->  demographics-map
demographics-map.tar.bz   ->  demographics-map
demographics-map.tar.zip  ->  demographics-map
demographics-map.tar.ball ->  demographics-map

暫無
暫無

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

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