Extract number from string in Ruby

后端 未结 7 2104
既然无缘
既然无缘 2020-12-02 10:59

I\'m using this code:

s = line.match( /ABCD(\\d{4})/ ).values_at( 1 )[0] 

To extract numbers from strings like:

ABCD1234
AB         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 11:49

    there is even simpler solution

    line.scan(/\d+/).first
    

提交回复
热议问题