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

197
Visualizações
How do I move nested leading spaces with regex/javascript?

Can/how do you do a multipart regex replace that looks for content within some tags then moves any space padding outside of the tags?

sample start string:

random text to ignore** some text **other text to ignore** other important text** blah blah blah

result:

random text to ignore **some text** other text to ignore **other important text** blah blah blah

basically trying to help a markdown to html library parse correctly where it is having trouble with spaces right after MD age so i want to do a quick scrub first. The conversion will be done in python with markdown2 or in javascript with showdown.js.

I am hoping for a syntax like s.replace(regex, '$1**$2**$3') where 1 and 3 would be spaces within the tags, if they exist

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use

text.replace(/\*{2}(\s*)(.*?)(\s*)\*{2}/g, '$1**$2**$3')

See the regex demo. Details:

  • \*{2} - a ** string
  • (\s*) - Group 1 ($1): zero or more whitespaces
  • (.*?) - Group 2: any zero or more chars other than line break chars as few as possible (use [^]*? or [\w\W]*? to match across line breaks)
  • (\s*) - Group 3 ($3): zero or more whitespaces
  • \*{2} - a ** string

See a JavaScript demo:

const text = "random text to ignore** some text **other text to ignore** other important text** blah blah blah";
console.log(text.replace(/\*{2}(\s*)(.*?)(\s*)\*{2}/g, '$1**$2**$3'));

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