URL स्ट्रिंग टेस्ट करने के लिए, रेगुलर एक्सप्रेशन का उपयोग करें।
उदाहरण
निम्नलिखित कोड है:
var regularExpressionForURL = /^https?:\/\//i;
var originalURL1 = "https://www.example.com/index";
var originalURL2 = "/index";
if (regularExpressionForURL.test(originalURL1)) {
console.log("This is absolute URL");
} else {
console.log("This is relative URL");
}
if (regularExpressionForURL.test(originalURL2)) {
console.log("This is absolute URL");
} else {
console.log("This is relative URL");
}
उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js
यहां, मेरा फ़ाइल नाम demo266.js है।
आउटपुट
यह कंसोल पर निम्नलिखित आउटपुट देगा:
PS C:\Users\Amit\javascript-code> node demo266.js This is absolute URL This is relative URL