본문 바로가기
프로그래밍/Ruby

Ruby - String에서 Number성분만 추리기

by 리나그(ReenAG) 2021. 12. 29.
728x90
반응형

https://stackoverflow.com/questions/2640819/extract-number-from-string-in-ruby/59238529

 

Extract number from string in Ruby

I'm using this code: s = line.match( /ABCD(\d{4})/ ).values_at( 1 )[0] To extract numbers from strings like: ABCD1234 ABCD1235 ABCD1236 etc. It works, but I wonder what other alternative I h...

stackoverflow.com

그중에서

line.delete("^0-9")

이게 제일 간단하고 좋아보임!

728x90
반응형