Forum: Ruby Ruby Regex

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F16e67cf8c0d59e1b98f5ba46d84b31d?d=identicon&s=25 Sriram Varahan (sriram)
on 2009-04-09 16:44
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...
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-09 16:51
(Received via mailing list)
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
F16e67cf8c0d59e1b98f5ba46d84b31d?d=identicon&s=25 Sriram Varahan (sriram)
on 2009-04-09 17:01
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...
This topic is locked and can not be replied to.