regex issues and up gradation Ruby ,Rails and gem

hi all,

i am getting the following warning for “numeric_slug = /[1]+$/” 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.


  1. 0-9 ↩︎

hi all,

i am getting the following warning for “numeric_slug = /[1]+$/” 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 = /[2]+$/

=> /[3]+$/

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 = /[4]+$/

=> /[5]+$/

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 = /[6]+$/

=> /[7]+$/

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


  1. 0-9 ↩︎

  2. 0-9 ↩︎

  3. 0-9 ↩︎

  4. -0-9 ↩︎

  5. -0-9 ↩︎

  6. 0-9- ↩︎

  7. 0-9- ↩︎