Regular expression help needed

I’m trying to write a regular expression for a ruby program. What it
needs to match is:

  0,,\a   where 0 is any digit, then 2 commas, a backslash, then any

letter.

I have one that works if the expression didn’t have the backslash (which
isn’t an escape character, but a literal character):

if $inrec =~ /[[:digit:]],[[:alpha:]]/

I’ve tried

if $inrec =~ /[[:digit:]],\[[:alpha:]]/

and

if $inrec =~ /[[:digit:]],[[:alpha:]]/

but neither works. Any ideas would be appreciated!

Peter V. wrote:

but neither works.
Works here.

puts “Works!” if ‘0,\a’ =~ /[[:digit:]],\[[:alpha:]]/
Works!

Sebastian, right you are! I must have made a typo. Sorry about that!

Sebastian H. wrote:

Peter V. wrote:

but neither works.
Works here.

puts “Works!” if ‘0,\a’ =~ /[[:digit:]],\[[:alpha:]]/
Works!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs