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

202
Vistas
replace words that starts with "(uuid: )"

I would like to replace text using javascript/regex

"TV "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched off."

with

TV 'my-samsung' is already switched off.

by removing text (UUID: ) and replace " with '

Looks like regex can be used

  \([\s\S]*?\) 

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

or have also tried using replace method in JS

   str = str.replace("(UUID", "");
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use

const str = '" "Tv "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched-off""';
console.log(
   str.replace(/\s*\(UUID:[^()]*\)/g, '').replace(/^[\s"]+|[\s"]+$/g, '').replaceAll('"', "'")
)

See the first regex demo. It matches

  • \s* - zero or more whitespaces
  • \(UUID: - (UUID: string
  • [^()]* - zero or more chars other than ( and )
  • \) - a ) char.

The g flag makes it replace all occurrences.

The second regex removes trailing and leading whitespace and double quotation marks:

  • ^[\s"]+ - one or more whitespaces and double quotes at the start of string
  • | - or
  • [\s"]+$ - one or more whitespaces and double quotes at the end of string.

The .replaceAll('"', "'") is necessary to replace all " with ' chars.

It is not a good idea to merge these two operations into one as the replacements are different. Here is how it could be done, just for learning purposes:

const str = '" "Tv "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched-off""';
console.log(
   str.replace(/^[\s"]+|[\s"]+$|\s*\(UUID:[^()]*\)|(")/g, (x,y) => y ? "'" : "")
)

That is, " is captured into Group 1, the replacement is now a callable, where x is the whole match and y is the Group 1 contents. If Group 1 matched, the replacement is ', else, the replacement is an empty string (to remove the match found).

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can try this

str.replace(/\(.*?\)/, "")
str.replace(/\(.*?\)/, "with")

--- update ---

const str = `"TV "my-samsung" (UUID: a1c3bbc1d27c5be8:8baabe2fa7f5d9ca) is already switched off."`;
const a = str.replace(/"(.*?)\(.*\)(.*)"/, (a, b, c) => {
    return b.replace(/"/g, "'") + c
});
console.log(a); //TV 'my-samsung' is already switched off. 
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