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

161
Views
¿Cómo agregar espacio entre la moneda y la cantidad que está dentro de una cadena?

Mi cadena en Ruby contiene moneda y cantidad.

Compré un artículo a USD500.80 en la tienda en línea store 123X87

Estoy esperando el siguiente resultado

Compré un artículo a USD 500.80 en la tienda en línea store 123X87

Intenté con Regex pero no tuve éxito.

 str = "I have purchased and item at USD500.80 from online store store 123X87" str.gsub(/\d+/, ' \0 ') # wrong result "I have purchased and item at USD 500 . 80 from online store store 123 X 87 "

No estoy seguro de qué moneda contiene esa cadena. Solo se moneda y monto no tienen espacio.

 str = "I have purchased and item at EUR500.80 from online store store 123X88" str = "I have purchased and item at GBP500.80 from online store store 123X88"
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cambiaría la expresión regular para escanear explícitamente todos los códigos de moneda conocidos. Cualquier expresión regular demasiado generalizada (como \w+\d+ , por ejemplo) está obligada a romper otras partes de la cadena, como los números de pedido.

 str = "I have purchased and item at USD500.80 from online store store 123X87" str.gsub(/(USD|EUR)(\d+)/, '\1 \2') # => "I have purchased and item at USD 500.80 from online store store 123X87"
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!