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

128
Views
Regex to get/replace strings in between two character sets in JavaScript

I have a string containing external url links like

.listView a.toggle::after { content: " "; background: url("/test/images/up_small.svg") center center no-repeat; }

I want to grab the text between the url tags like

/test/images/up_small.svg

I tried like

a.split(new RegExp("[^(url)\(\".*\"]"))

but it did not work.

How can I get the external url and if needed replace the same with something else? in JavaScript

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

0

You can search using this regex with 2 capture groups:

(.* url\(")[^"]+(".*)

And replace using $1http://example.com$2 where http://example.com is replacement.

RegEx Demo

Code:

var s = '.listView a.toggle::after { content: " "; background: url("/test/images/up_small.svg") center center no-repeat; }';

var r = s.replace(/(.* url\(")[^"]+(".*)/, '$1http://example.com$2');

console.log(r);

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!