通过 JavaScript 正则表达式验证 Tutorialspoint URL?
javascriptweb developmentfront end technologyobject oriented programming更新于 2026/2/14 10:20:17
要验证特定 URL,请使用正则表达式。
示例
代码如下 −
function validateSoundURL(myURL) {
var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/;
return myURL.match(regularExpression) && myURL.match(regularExpression)[2]
}
console.log(validateSoundURL("https://tutorialspoint.com/index"));
console.log(validateSoundURL("https://tutorialspoint.com/java"));
要运行上述程序,您需要使用以下命令 −
node fileName.js.
这里,文件名是 demo259.js。
输出
这将在控制台上产生以下输出 −
PS C:\Users\Amit\javascript-code> node demo259.js index java
相关文章
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.cainiaomax.com/javascript/

