Forum: Ruby Regular Expression issue

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
D4f5ba376e2d4e280889ed462939f632?d=identicon&s=25 anon1m0us (Guest)
on 2007-02-02 17:05
(Received via mailing list)
Hi; I created a program that needs to parse through multiple files
looking for users and groups. The users are listed with Employee
Number and Name and then Groups. The format is as follows:

C008658 Smith,John
C009525 Smith, Jane
C014259 Doe, Joe
C044888 Doe, Jack
*******************************************************(yes, the stars
are part of the file)

Outsource Access Control Sheet - Finance
Project Manager: Gilmore, Happy (0083234)
Date of first approval: Not approved
Date of last update: First Update
Type: LAN
Groups: Yes-Some-Type-of_Group

I need to capture, the employee ID, Name, and Groups. My Current
program is not working to well. Here is ONE of the version of the
program I am working on to get it to work.
CemployeeS=" ""D:\\Finance.txt").each { |user|
  while user.scan(/^[*]+/)

    puts CemployeeID[counter]
    puts CemployeeName[counter]

843ec449f7f92801917ec535807624b1?d=identicon&s=25 unknown (Guest)
on 2007-02-02 18:41
(Received via mailing list)
Instead of capturing each data element one at a time with separate
user.scan's, it's easier to create a match object from a single
regular expression that contains match groups.  You can then access
the results of the match group by using $1, $2, etc.
Try this:
CemployeeS=" ""D:\\finance.txt").each { |user|
  m = /^([C]\d+)\s(\w+,\s?\w+)/.match(user)
  if m
      puts "Name: #{CemployeeName[counter]} ID:

Hope that helps-

This topic is locked and can not be replied to.