Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda