2016-10-06 33 views
0

我有一個像下面正則表達式匹配給定的字符串

字符串

https://maps.googleapis.com/maps/api/streetview?channel=rdc-ldp-streetview&client=sourcemaps

如何檢查我的變量值是否返回兩勝:

https://maps.googleapis.com/maps/api/streetview

+0

參考'String.indexOf()'會幫你 –

+0

你並不需要固定的字符串正則表達式。 –

+1

可能重複[如何檢查一個字符串是否包含JavaScript中的另一個子字符串?](http://stackoverflow.com/questions/1789945/how-to-check-if-one-string-contains-another-substring-in -javascript) –

回答

0

ES6

str.startsWith('https://maps.googleapis.com/maps/api/streetview'); 

ES5

str.indexOf('https://maps.googleapis.com/maps/api/streetview') === 0