2017-03-27 87 views
0

的JavaScript文件的比賽我有任務的gulp.src但我想匹配所有包含某個字作爲前綴如文件:包含某些前綴

gulp.src('./mydir/project.build-blessed1.css') 

但可以有N個文件與不同的數字,祝福1,祝福2,祝福3

我怎樣才能讓它匹配任何文件,以該開頭並具有.css擴展名在同一行,而不使用函數?

+0

您需要一個glob模式* Glob *,它可以通配符匹配您的模式(搜索glob或gulp-glob –

+1

我們只匹配匹配模式的文件'./mydir/project.build-blessed #.css'? – Feathercrown

+0

試試las tIndexOf,https://www.w3schools.com/jsref/jsref_lastindexof.asp – SPlatten

回答

0

正如Splatten建議的那樣,您可以使用string.lastIndexOf方法。在你的情況下:

var string = 'i want to do something!' 

if (string.lastIndexOf('something') !== -1) { 
    //keyword was found, meaning it's in the string 
} else { 
    //keyword was not found 
} 

lastIndexOf返回他找到關鍵字的索引。

gulp.src('./mydir/project.build-blessed*.css') 

應該工作

您可以:如果你不使用一口一個老implemetation你甚至可以在路徑中使用「*」作爲通配符所以像