# Capture information with a split and maybe a match?

**URL:** <https://www.ruby-forum.com/t/capture-information-with-a-split-and-maybe-a-match/81965>\
**Category:** Ruby\
**Created:** [January 16, 2007, 4:56pm UTC](https://www.ruby-forum.com/t/capture-information-with-a-split-and-maybe-a-match/81965 "2007-01-16T16:56:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon1m0us](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@anon1m0us](https://www.ruby-forum.com/u/anon1m0us)\
**Post date:** [January 16, 2007, 4:56pm UTC](https://www.ruby-forum.com/t/capture-information-with-a-split-and-maybe-a-match/81965/1 "2007-01-16T16:56:27Z")

</div>

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](http://abc.com).

Group name NA-CITRIX  
Comment Owner:John D.

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,

---

<div class="post-metadata">

**Author:** ![anon1m0us](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@anon1m0us](https://www.ruby-forum.com/u/anon1m0us)\
**Post date:** [April 5, 2007, 4:03pm UTC](https://www.ruby-forum.com/t/capture-information-with-a-split-and-maybe-a-match/81965/2 "2007-04-05T16:03:53Z")

</div>

On 1/17/07, anon1m0us [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

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\_stdtypes.html#S4](http://www.rubycentral.com/book/tut_stdtypes.html#S4)

Harry

–

> **[Kakueki.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=kakueki.com)**
>
> Start using this domain right away. Straightforward domain shopping experience. Quick access to your domain.

Japanese Ruby List Subjects in English

---

<div class="post-metadata">

**Author:** ![anon1m0us](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@anon1m0us](https://www.ruby-forum.com/u/anon1m0us)\
**Post date:** [April 5, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/capture-information-with-a-split-and-maybe-a-match/81965/3 "2007-04-05T18:33:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon1m0us](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d07c76/32.png) [@anon1m0us](https://www.ruby-forum.com/u/anon1m0us)\
**Post date:** [April 5, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/capture-information-with-a-split-and-maybe-a-match/81965/4 "2007-04-05T20:21:21Z")

</div>

On Apr 5, 12:33 pm, Andrew J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> result\_of\_na\_citrix = `net group na-citrix /dom`[/-+\n(.\*)/m,1].split(" ")
> 
> cheers,  
> andrew
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

I’d suggest:  
separator =  
“-------------------------------------------------------------------------------  
\n”  
junk,users = `net group na-citrix /dom`.split(separator)  
user\_array = users.split(’ ')

YMMV

Cheers  
Chris
