Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
How to check if a URL string contains either of 2 substrings?

How can I check if a string contains either one of 2 other strings? For example, I want to check if a URL contains either one of these string localhost or 10.0.2.2

http://localhost:5000 -> true
10.0.2.2:5000 -> true
dasdasdasdasdlocalhostdasdasd -> true
dasdasdasd10.0.2.2:5000dasdasd -> true
http://example.com -> false
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

if (/localhost|10.0.2.2/.test(URL)) {
   //your code
}
about 4 years ago · Juan Pablo Isaza Report

0

You could use .some() to determine if a string contains some of the keywords.

const urls = ['10.0.2.2:5000', 'dasdasdasdasdlocalhostdasdasd', 'dasdasdasd10.0.2.2:5000dasdasd', 'http://example.com'];

const keywords = ['localhost', '10.0.2.2'];

const urlsWithKeywords = urls.filter(url => {
  return keywords.some(keyword => url.includes(keyword));
});

console.log(urlsWithKeywords);

about 4 years ago · Juan Pablo Isaza Report

0

var pattern = /localhost|10.0.2.2/;
var url= "your url here";

if (pattern.test(url)) {
    // That means return true
   //your rest of the code
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!