Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
GSUB reemplaza 3 o más caracteres repetidos

Se agradecería un poco de ayuda con una expresión regular de gsub en Ruby. Necesito reemplazar 3 o más barras diagonales "//////" con solo 2 barras diagonales "//" en una cadena de texto. Sin embargo, una barra inclinada simple y dos barras inclinadas deben omitirse y dejarse como están.

mis datos se parecen a este jeep/grand cherokee////////hyundai/////harley davidson//bmw y deben convertirse a jeep/grand cherokee//hyundai//harley davidson//bmw

No tengo mucha experiencia con el uso de gsub regex, aquí hay algunas cosas que he probado, pero eliminan todas las barras o agregan demasiadas.

 vehicles = vehicles.gsub(/[\/\\1{3,}]/, "") vehicles = vehicles.gsub(/[\/\2+]/, "//") vehicles = vehicles.gsub(/[\/{3,}]/,"//")
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cuando encierra todo el patrón entre corchetes, hace que coincida con un solo carácter.

Sus expresiones regulares significan:

  • [\/\\1{3,}] - un solo carácter, / , \ , 1 , { , 3 , o }
  • [\/\2+] - / , \u0002 carácter o +
  • [\/{3,}] - / , { , 3 , o }

Puedes usar

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

Vea la demostración de Ruby en línea .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!