Regular expression help needed

Discussion in 'Ruby' started by Peter Vanderhaden, Oct 3, 2007.

  1. 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!
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Vanderhaden, Oct 3, 2007
    #1
    1. Advertising

  2. Peter Vanderhaden wrote:
    > 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!


    --
    NP: My Dying Bride - Two Winters Only
    Jabber:
    ICQ: 205544826
     
    Sebastian Hungerecker, Oct 3, 2007
    #2
    1. Advertising

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

    Sebastian Hungerecker wrote:
    > Peter Vanderhaden wrote:
    >> but neither works.

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

    > Works!


    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Vanderhaden, Oct 3, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,355
  2. David Cho
    Replies:
    4
    Views:
    421
    David Cho
    Feb 15, 2005
  3. Chanchal
    Replies:
    1
    Views:
    500
    NullBock
    Dec 13, 2005
  4. pekka niiranen
    Replies:
    5
    Views:
    551
    Paul McGuire
    Oct 20, 2004
  5. ragz_82
    Replies:
    1
    Views:
    313
    ragz_82
    Aug 4, 2009
Loading...

Share This Page