+ 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

15th Apr 2022, 1:09 AM
conta rascunho
conta rascunho - avatar
6 Answers
+ 2
Write this code instead. x.gsub!(/[[:punct:]]/, "") #x.gsub!(/\W+/, "")
15th Apr 2022, 1:39 AM
SoloProg
SoloProg - avatar
+ 2
SoloProg SoloProg Thanks for it. Now, thats code is working better! x = gets.chomp() puts x.gsub(/[[:punct:][0-9]]/, "").reverse
15th Apr 2022, 2:47 AM
conta rascunho
conta rascunho - avatar
+ 2
ANONYMOUS , your code is excelente.
15th Apr 2022, 2:51 AM
conta rascunho
conta rascunho - avatar
+ 1
Or this puts gets.gsub(/[^A-Za-z ]/, '').reverse
15th Apr 2022, 1:46 AM
JOKER
JOKER - avatar
+ 1
SoloProg, can you explain it for me? i don't know what's the :punct: mean...
15th Apr 2022, 2:00 AM
conta rascunho
conta rascunho - avatar
+ 1
https://ruby-doc.org/core-3.1.1/Regexp.html Have a read /[[:punct:]]/ - Punctuation character
15th Apr 2022, 2:26 AM
SoloProg
SoloProg - avatar