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

156
Views
How to add spacing between currency and amount which is inside a string?

My string in Ruby contains currency and amount.

I have purchased and item at USD500.80 from online store store 123X87

I am expecting following result

I have purchased and item at USD 500.80 from online store store 123X87

I tried with Regex but not succeed.

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 "

I am not sure what currency that string contains. I only know currency and amount do not have space.

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

I'd change the regex to scan for all known currency codes explicitly. Any over-generalized regex (such as \w+\d+, for example) is bound to break other parts of the string, like order numbers.

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!