通过 JavaScript 正则表达式验证 Tutorialspoint URL?
若要验证特定 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP