• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

197
Vistas
Javascript - how to replace an escape character followed by a 'G' in a string

I have the following string 'Ganaway\Gannaway\Gansway' from a text file where I need to replace the escape character(s) with ' or '.

I've found answers here on Stackoverflow that suggest:

const name = 'Ganaway\Gannaway\Gansway';
name.replace(/\//g, ' or ');

Fiddle

However when I debug it the name is already stripped automatically of the escape character before it reaches the .replace() code.

The result should be 'Ganaway or Gannaway or Gansway' but its unfortunately 'GanawayGannawayGansway'.

Update:

The strings originate from a GEDCOM file which was exported from a genealogy website called Ancestry.com - here are some examples of the original text, it's not only the 'G' but various others that lead to

Regular expression is invalid: PCRE does not support \L, \l, \N{name}, \U, or \u

errors:

1 NAME Emma Mae\May /Ganaway\Gannaway\Gansway/

or

1 NAME Niecy\Nicy Ann /Holy/

or

1 NAME Peggy Jo /Stewart\Uttrell/

about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You will have to use this syntax

const name = String.raw`Ganaway\Gannaway\Gansway`;
name.replace(/\\/g, ' or ');
about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda