regex issues and up gradation Ruby ,Rails and gem

3 views
Skip to first unread message

sachin kewale

unread,
Dec 27, 2011, 1:04:45 AM12/27/11
to rubyonra...@googlegroups.com
hi all,

  i am getting the following warning for "numeric_slug = /^[0-9]+$/" this line in my model class,
  "warning: character class has `-' without escape"
 
  can anyone know the what is the escape character used in regex ?
  i am using Ruby:1.8.7,gem:1.6.2,Rails:2.3.11.
  Also, i want to up grade my current version of Ruby ,Rails and gem with latest one ,but i don't  know what are compatible and stable latest version for ruby and rails with  
  rubygem ?
  can anyone have any suggestion on this for up gradation of the environment ?

 thanks in advanced.

--
Regards
Sachin S. Kewale

Peter Vandenabeele

unread,
Dec 27, 2011, 7:58:13 AM12/27/11
to rubyonra...@googlegroups.com
On Tue, Dec 27, 2011 at 7:04 AM, sachin kewale <sachin...@gmail.com> wrote:
hi all,

  i am getting the following warning for "numeric_slug = /^[0-9]+$/" this line in my model class,
  "warning: character class has `-' without escape"

Strange ... I copy/pasted your piece of code, and works fine here.
The '-' acts as a range (from '0' to '9').

peterv@ASUS:~/b$ rvm use 1.8.7
Using /home/peterv/.rvm/gems/ruby-1.8.7-p352
peterv@ASUS:~/b$ irb
001:0> numeric_slug = /^[0-9]+$/
=> /^[0-9]+$/
002:0> numeric_slug.match("1234")
=> #<MatchData "1234">
003:0> numeric_slug.match("1234aa")
=> nil
 
 
  can anyone know the what is the escape character used in regex ?
  i am using Ruby:1.8.7,gem:1.6.2,Rails:2.3.11.

The escape character is a backslash. So, if you really wanted to match a '-'
you could do 2 things:
* escape the '-' as '\-'
* place the '-' the last entry in the character class

 peterv@ASUS:~/b$ rvm use 1.8.7 # also tested in 1.9.3
Using /home/peterv/.rvm/gems/ruby-1.8.7-p352
peterv@ASUS:~/b$ irb
001:0> numeric_and_dash = /^[\-0-9]+$/
=> /^[\-0-9]+$/
002:0> numeric_and_dash.match("01234-5678-91")
=> #<MatchData "01234-5678-91">
003:0> numeric_and_dash.match("0+4")
=> nil
004:0> numeric_and_dash = /^[0-9-]+$/
=> /^[0-9-]+$/
005:0> numeric_and_dash.match("01234-5678-91")
=> #<MatchData "01234-5678-91">


  Also, i want to up grade my current version of Ruby ,Rails and gem with latest one ,but i don't  know what are compatible and stable latest version for ruby and rails with  
  rubygem ?

I currently use the combination below from up-to-date rvm. For development,
best is to set-up rvm , if you did not already have it.

Current up-to-date setting with rvm is:

rvm : version 1.10.0           # rvm get latest
ruby : 1.9.3[-p0]                  # rvm list known | egrep '\[ruby\-\].*\[' | tail -1
rails : 3.1.3   (close to 3.2) # gem list -r rails | grep 'rails '
rubygems : 1.8.10              # rvm rubygems current

HTH,

Peter

--
Peter Vandenabeele
http://twitter.com/peter_v
Reply all
Reply to author
Forward
0 new messages