E
E
eldar_web2015-12-29 12:24:16
ruby
eldar_web, 2015-12-29 12:24:16

How can you truncate a string with commas in Ruby?

There used to be a site rubydev.ru, and there was almost everything about ruby, but right now there is no such thing.
Here, for example, there is a line:
str='Область, город, улица'
How can you leave the text, cutting off the rest, which is up to the second comma, starting from the end ?
In our case, it should remain like this: str='city, street'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Korolev, 2015-12-29
@eldar_web

One of the options:
str.gsub(/^([а-яА-Я]+, )?/,'')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question