Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
How to insert value after specific text in the string

I would like to add value to my URL after the specific text. How I can achieve this?

I found a solution where I can slice and add values but I don't have the index fixed in this URL.

const url = 'www.website.com/api/test1/test2';

const url = 'www.website.test.com/api/test1/test2/test3';

const output1 = 'www.website.com/api/ha/test1/test2';

const output2 = 'www.website.test.com/api/ha/test1/test2/test3';
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I prefer working with URL

const url1 = new URL('https://www.website.com/api/test1/test2');
const pn =  url1.pathname.split("/")
pn.splice(2,0,'ha')
url1.pathname=pn.join("/");
console.log(url1.href)

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want to add a certain value after a certain string you can simply replace the known value with the new string:

url.replace('/api', '/api/ha')
about 4 years ago · Juan Pablo Isaza Relatório

0

If you don't have a fixed index, you should use Regex to search the string. Could look like this:

/(www.\D+\/api\/)[\D\d\/]+/gm

This code would put the before and after into a group and you can then do

group1 + yourstring + group2

to add it together.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda