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

196
Visualizações
RegEx how to match everything exclude a string in a function

How can I exclude a string from the match in regex?

Input:

functionXY("Hello World"); 

Match:

functionXY();

i got this far with my regex expression:

/functionXY[(][)][;]/gm

but can't find the correct expression to exclude the string "Hello World" in the match.

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

0

You can use a regex to match everything inside the brackets, then use replace.

const str = 'functionXY("Hello World");';

const regex = /(?<=functionXY[(]).+(?=[)][;])/gm;

const res = str.replace(regex, '')
console.log(res)

about 4 years ago · Juan Pablo Isaza Relatório

0

Your pattern functionXY[(][)][;] uses square brackets for single characters and only matches functionXY();

Instead you can use 2 capture groups to capture what you want to keep, and match the double quotes and all chars other than double quotes that you don't want to keep.

In the replacement use 2 capture groups $1$2

(functionXY\()"[^"]*"(\);)

Regex demo

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