From: Ralph Mason Date: 2001-12-26T17:39:43+09:00 Subject: [ruby-talk:29435] Re: Help with Regular Expression Hi Vincent, you can just use a normal test eg if a =~ /\d+/ ....... A matches else ...... A doesnt match end or perhaps an inline version a=a.to_i if a=~/\d+/ or a=$1.to_i if a=~/(\d+)/ This is because a regular expresion returns nil if there is no match otherwise the offset of the match Ralph ----- Origi/nal Message ----- From: "Vincent Foley" To: "ruby-talk ML" Sent: Wednesday, December 26, 2001 5:11 PM Subject: [ruby-talk:29431] Help with Regular Expression > Hi, > > I would like to know how I would check if a variable's content matches a > regular expression. Example (complete the code): > > [code] > #!/usr/bin/env ruby > > a = gets.chomp > > # Complete here. I want to know if a is an integer with regular > # expressions (/\d*/). Can I do that? How? > > [/code] > > > -- > > Vincent Foley-Bourgon > Email: gnuvince@yahoo.ca > Homepage: http://darkhost.mine.nu:81 >