通过JavaScript正则表达式验证Tutorialspoint URL?
要验证特定的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
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志