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

262
Vistas
How to remove part of string that is in parentheses?

I have a string from which I want to remove the last parentheses "(bob)". So far I use this code to return the value within these parentheses:

const str = "Hello my name is (john) (doe) (bob)";
const result = str.split('(').pop().split(')')[0];
console.log(result);

How would I be able to return the string without these last parentheses?

about 4 years ago · Santiago Gelvez
3 Respuestas
Responde la pregunta

0

const str = 'Hello my name is (john) (doe) (bob)';
const lastIdxS = str.lastIndexOf('(');

console.log(str.slice(0, lastIdxS).trim());

about 4 years ago · Santiago Gelvez Denunciar

0

Source: How to remove the last word in a string using JavaScript

Possibly not the cleanest solution, but if you always want to remove the text behind last parentheses, it will work.

   var str = "Hello my name is (john) (doe) (bob)";
   var lastIndex = str.lastIndexOf("(");

   str = str.substring(0, lastIndex);
   console.log(str);

about 4 years ago · Santiago Gelvez Denunciar

0

You can match the last occurrence of the parentthesis, and replace with capture group 1 that contains all that comea before it:

^(.*)\([^()]*\)

Regex demo

about 4 years ago · Santiago Gelvez 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