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

429
Vistas
GSUB replace 3 or more repeating characters

A little help would be appreciated with a gsub regex in ruby. I need to replace 3 or more forward slashes "//////" with just 2 forward slashes "//" in a string of text. However, a single forward slash and double forward slashes should be skipped and left as is.

my data looks like this jeep/grand cherokee////////hyundai/////harley davidson//bmw and should be converted to jeep/grand cherokee//hyundai//harley davidson//bmw

I don't have much experience with using gsub regex's, here's a few things I've tried but they either strip out all forward slashes or add in too many.

  vehicles = vehicles.gsub(/[\/\\1{3,}]/, "")

  vehicles = vehicles.gsub(/[\/\2+]/, "//")

  vehicles = vehicles.gsub(/[\/{3,}]/,"//")
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

When you enclose the whole pattern inside square brackets, you make it match a single char.

Your regexps mean:

  • [\/\\1{3,}] - a single char, /, \, 1, {, 3, , or }
  • [\/\2+] - /, \u0002 char or +
  • [\/{3,}] - /, {, 3, , or }

You can use

s.gsub(/\/{3,}/, '//')

See the Ruby demo online.

over 4 years ago · Santiago Trujillo 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