bcparanj@gmail.com
5/29/2007 11:11:00 PM
The regexp: /foo\ (\d+)\-?(\d*)/
seems to work. Still testing...
On May 29, 3:57 pm, "Tim Pease" <tim.pe...@gmail.com> wrote:
> On 5/29/07, bcpar...@gmail.com <bcpar...@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"