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

242
Visualizações
Regex, matching backticks not nested within triple backticks

I'm trying to match strings that are surrounded by backtick's but they aren't surrounded by triple backtick's.

For example:

match: `I should be matched`

should not match: ``` `Hello world` ```

This is what I've tried so far: https://regex101.com/r/P4MhiM/1

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

0

i get pass this test case

first capture all match in single quote

\`(?:.+)\`

second filter the matchs only char not backticks nor white space

\`(?:[^\`||\s]+)\`

https://regex101.com/r/oVE7zi/1

about 4 years ago · Juan Pablo Isaza Relatório

0

Match and capture a part of the match, then use custom logic in the replacement:

const text = "\n``` `Hello world` ```\n\n\n`Matched!`\n";
const rx = /```.*?```|`([^`\n]+)`/g;
console.log(
  text.replace(rx, (x, y) => y ? `<code>${y}</code>` : x)
)

See the regex demo. Details:

  • ```.*?``` - strings between triple backticks (with no line breaks in between backticks)
  • | - or
  • `([^`\n]+)` - strings between backticks without line break chars.
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