Matching group names

I am trying to capture a users group. I use dsquery and the output is
a bunch of groups starting with the words CN= group name followed by
a comma.
I need the group name from after CN= and before the FIRST comma. How
can i do it. I tried spilts, scans, and matches with out much success.

anon1m0us wrote:

I am trying to capture a users group. I use dsquery and the output is
a bunch of groups starting with the words CN= group name followed by
a comma.
I need the group name from after CN= and before the FIRST comma. How
can i do it. I tried spilts, scans, and matches with out much success.

You didn't give a complete example of what is returned by dsquery so I'm going to have take a guess at a working single regular expression match:

group_name = dsquery_str.gsub(/^CN=(.*?),.*$/, '\1')

If the ".*?" pattern is not working correctly you can do it the long way like this:

values = dsquery_str.split(/,/)
group_name = values[0].gsub(/^CN=(.*)/, '\1')

That will remove any confusion the commas can cause in the pattern matching.