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

159
Views
How to implement a function that matches a specific paragraph in JavaScript?

full url : abc.com/product/123

find url : abc.com/product

I want to return true if the full url contains find url

The condition must match the sentences of find url and the words in the full url perfectly.

fullurl.indexOf('abc') // this find true It is a condition that only certain words should not be split.

I want the result value

fullurl = 'abc.com/product/123'; 
findurl = 'abc.com/product';

fullurl.indexOf('abc'); // this find false 
fullurl.indexOf('pro'); // this find false 
fullurl.indexOf('abc.com'); // this find false 
fullurl.indexOf('abc.com/product'); // this true This result is the return value I want

I can't get the result I want with the indexOf function alone. What should I do?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This will return true if fullurl contains findurl.

I used regex, if you want to change the findurl you need to edit the regex code.

function matchUrl(fullurl) {
  reg = /\babc.com\/product\b/;
  if (fullurl.match(reg)) {
    return true;
  }
  return false;
}

Check this out to further understand the regex I used.

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!