Regex to split an array in Ruby based on Pattern -


this more of "what regex use" rather semantics question.

i have following string :

moneystring = "¥10,100 yen,€100.00 eu,$100.00 us" 

and need split on comma. however, don't want comma in 10,000 yen separated 2 arrays.

currently, if moneystring.split(',')

i : [¥10, 100 yen, €100.00 eu, $100.00 us] different array values. want :

[¥10100 yen, €100.00 eu, $100.00 us]

can show me how regex correct? i'm sorry, complete newbie stuff.

you split on commas not preceded number, using negative lookbehind.

moneystring = "¥10,100 yen,€100.00 eu,$100.00 us"  puts moneystring.split(/(?<!\d),/)  # ¥10,100 yen # €100.00 eu # $100.00 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -