Compré un artículo a USD500.80 en la tienda en línea store 123X87
Compré un artículo a USD 500.80 en la tienda en línea store 123X87
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"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"