要验证特定的URL,请使用正则表达式。
代码如下-
function validateSoundURL(myURL) {
var regularExpression = /^https?:\/\/(nhooo\.com)\/(.*)$/;
return myURL.match(regularExpression) && myURL.match(regularExpression)[2]
}
console.log(validateSoundURL("https://nhooo.com/index"));
console.log(validateSoundURL("https://nhooo.com/java"));要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo259.js。
输出结果
这将在控制台上产生以下输出-
PS C:\Users\Amit\javascript-code> node demo259.js index java