Regular expression help needed

  • Thread starter Peter Vanderhaden
  • Start date
P

Peter Vanderhaden

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!
 
S

Sebastian Hungerecker

Peter said:
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've tried

if $inrec =~ /[[:digit:]],,\\[[:alpha:]]/
...
but neither works.

Works here.
puts "Works!" if '0,,\a' =~ /[[:digit:]],,\\[[:alpha:]]/
Works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top