Ruby Regex

Discussion in 'Ruby' started by Sriram Varahan, Apr 9, 2009.

  1. Hello,


    I am working on extracting some data from a file.
    Sample data in the file are as follows:

    Case 1: Direction abc,(xyz)
    Case 2: Direction fet

    I want to extract the content after Direction but before the comma(if
    present).
    The issue I am facing is that the comma is not always present.

    Otherwise a reg exp like:

    reg_exp = %r{Direction(.+),}

    would have given me the content.
    This would not work in the 2nd case.


    How to account for both the conditions.
    Any help would be appreciated...
    --
    Posted via http://www.ruby-forum.com/.
     
    Sriram Varahan, Apr 9, 2009
    #1
    1. Advertising

  2. On 09.04.2009 16:44, Sriram Varahan wrote:
    > Hello,
    >
    >
    > I am working on extracting some data from a file.
    > Sample data in the file are as follows:
    >
    > Case 1: Direction abc,(xyz)
    > Case 2: Direction fet
    >
    > I want to extract the content after Direction but before the comma(if
    > present).
    > The issue I am facing is that the comma is not always present.
    >
    > Otherwise a reg exp like:
    >
    > reg_exp = %r{Direction(.+),}
    >
    > would have given me the content.
    > This would not work in the 2nd case.
    >
    >
    > How to account for both the conditions.
    > Any help would be appreciated...


    /Direction\s+([^,]+)/

    Cheers

    robert
     
    Robert Klemme, Apr 9, 2009
    #2
    1. Advertising

  3. Robert Klemme wrote:
    > On 09.04.2009 16:44, Sriram Varahan wrote:
    >> present).
    >> How to account for both the conditions.
    >> Any help would be appreciated...

    >
    > /Direction\s+([^,]+)/
    >
    > Cheers
    >
    > robert



    Hey Robert,

    Thanks a ton for ur help...
    It worked...
    --
    Posted via http://www.ruby-forum.com/.
     
    Sriram Varahan, Apr 9, 2009
    #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. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    724
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,650
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    614
  4. Xah Lee
    Replies:
    1
    Views:
    954
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    794
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page