[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Capture information with a split and maybe a match?

anon1m0us

1/16/2007 3:51:00 PM

Hi;
Here is my line of code that I need help in:
result_of_na_citrix=`net group na-citrix /dom`.split(" ")
This gets all the users in in it's own index split on a space.
However, there is a bunch of garbage (stuff that I do not need to
capture) before the names of the users are listed. Here is an example

The request will be processed at a domain controller for domain
abc.com.

Group name NA-CITRIX
Comment Owner:John Doe

Members

-------------------------------------------------------------------------------
The list of users begins here.


I need to get the list of users ONLY. Basically, to capture info AFTER
the dashes -----------. I did a 20.times do, but each group has a
different information. The ONLY consistent thing is the list of users
that start AFTER the dashes,

3 Answers

Harry

4/5/2007 2:03:00 PM

0

On 1/17/07, anon1m0us <anon1m0us@yahoo.com> wrote:
> However, there is a bunch of garbage (stuff that I do not need to
> capture) before the names of the users are listed. Here is an example
>
> The request will be processed at a domain controller for domain
> abc.com.
>
> Group name NA-CITRIX
> Comment Owner:John Doe
>
> Members
>
> -------------------------------------------------------------------------------
> The list of users begins here.
>
>
> I need to get the list of users ONLY. Basically, to capture info AFTER
> the dashes -----------. I did a 20.times do, but each group has a
> different information. The ONLY consistent thing is the list of users
> that start AFTER the dashes,
>
>
>

If I understand your question, something like this should help.


str = "Group name NA-CITRIX\nComment Owner:John Doe\nMembers\n" +
"-----------------------------------------------------" +
"--------------------------\nThe list of users begins here."

str =~ /.*?-{3,}.*?(\w.*)/m
puts $1



Look into regular expressions and adjust as necessary.
http://www.rubycentral.com/book/tut_stdtyp...

Harry


--

http://www.kakueki.com/ruby...
Japanese Ruby List Subjects in English

Andrew Johnson

4/5/2007 4:33:00 PM

0

anon1m0us wrote:
>
> I need to get the list of users ONLY. Basically, to capture info AFTER
> the dashes -----------. I did a 20.times do, but each group has a
> different information. The ONLY consistent thing is the list of users
> that start AFTER the dashes,

Use the String#[] method with a regex to just return the portion
following
the dashes, and split that:

result_of_na_citrix = `net group na-citrix
/dom`[/-+\n(.*)/m,1].split(" ")

cheers,
andrew

--
Posted via http://www.ruby-....

Chris Hulan

4/5/2007 6:16:00 PM

0

On Apr 5, 12:33 pm, Andrew Johnson <ajohn...@cpan.org> wrote:
> anon1m0us wrote:
>
> > I need to get the list of users ONLY. Basically, to capture info AFTER
> > the dashes -----------. I did a 20.times do, but each group has a
> > different information. The ONLY consistent thing is the list of users
> > that start AFTER the dashes,
>
> Use the String#[] method with a regex to just return the portion
> following
> the dashes, and split that:
>
> result_of_na_citrix = `net group na-citrix
> /dom`[/-+\n(.*)/m,1].split(" ")
>
> cheers,
> andrew
>
> --
> Posted viahttp://www.ruby-....

I'd suggest:
separator =
"-------------------------------------------------------------------------------
\n"
junk,users = `net group na-citrix /dom`.split(separator)
user_array = users.split(' ')

YMMV

Cheers
Chris