From: Tim Pease Date: 2007-05-30T07:57:35+09:00 Subject: Re: Regexp to extract number with hyphen On 5/29/07, bcparanj@gmail.com wrote: > I have a text with "foo 01-02" in a string. I want to extract foo > 01-02 using regexp. reg = /foo (\d+)/ only extracts foo with numbers > when there is no hyphen. > > reg = /foo (\d{1,})|(\-)|(\d{1,})/ only extracts foo 01. TIA. > "foo 01-02" =~ /(\d+)-(\d+)/ puts $1 #=> "01" puts $2 #=> "02"