JavaScript中的正则表达式以匹配给定的字符串

时间:2016-10-06 10:03:15

标签: javascript

我有一个如下所示的字符串

  

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

如何检查返回的变量值是否与:

匹配
  

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

1 个答案:

答案 0 :(得分:0)

ES6

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

ES5

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