+ 2
"the spy life."I have a with the ruby's code.
How i do: "the spy life". With the ruby? I tried do i myself, but, i had some problems... can you help me? The code: x = gets.chomp() x.gsub!(/\W+/, "") x.gsub!(/\d+/, "") x.reverse! puts x
6 Answers
+ 2
Write this code instead.
x.gsub!(/[[:punct:]]/, "") #x.gsub!(/\W+/, "")
+ 2
SoloProg SoloProg Thanks for it. Now, thats code is working better!
x = gets.chomp()
puts x.gsub(/[[:punct:][0-9]]/, "").reverse
+ 2
ANONYMOUS , your code is excelente.
+ 1
Or this
puts gets.gsub(/[^A-Za-z ]/, '').reverse
+ 1
SoloProg, can you explain it for me? i don't know what's the :punct: mean...
+ 1
https://ruby-doc.org/core-3.1.1/Regexp.html
Have a read
/[[:punct:]]/ - Punctuation character