If you’re not yet thinking in regex terms, you need to dissect and
describe your pattern, and then translate it into a regular
expression. Here’s a description, as I understand it.
zero or one of
(one or more non-comma characters)
a comma
one or more spaces
(three uppercase letters)
one or more spaces
(one or more non-comma characters)
etc.
Also, note that you can’t choose which capture will be $1, $2, etc.
They are assigned strictly in the order in which the left parentheses
appear, left to right (unless you use (? to suppress inclusion of a
particular group).
David
–
David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com
Ruby/Rails training, mentoring, consulting, code-review
Latest book: The Well-Grounded Rubyist (The Well-Grounded Rubyist)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.