On Feb 11, 2010, at 2:01 PM, John Gesimondo wrote: > Sorry about the confusion. Apparently I asked the question wrong. I > was > just looking for some help with the regular expression part. I didn't > know how to extract variables from a long string. > >> regex = %r{\%B(.*)\^(.*)/ [...and so on...] } > > This was quite helpful. I was able to figure this out: > > %r{\%B(\d*)\^(\S*)\/(\S*)\s([a-zA-Z])} > > So I think the problem is solved! Because I *think* I know how to > integrate this into my program. > > > Thanks for the help, and I'll be sure to include my attempts next > time. > And please let me know if you noticed anything wrong with that regex. > > John > -- > Posted via http://www.ruby-forum.com/. > Well, break it into parts... I'll use %r{ } for Regexp literals You also haven't captured all the information. Try this: starts with '%B' : %r{\A%B} >> iso = 6007503004905860 [always the same length] 16 digits iso = %r{(\d{16})} >> last_name = Gevimsedo [variable length, always following carrot >> symbol] last_name = %r{\^([^/]*)} >> first_name = Jrpn [variable length, always after slash] first_name = %r{/([^ ^]*)} >> middle_name = P [ either one letter, or non-existent after frist name >> separated by a space] middle_name = %r{(?: ([^ ^]))?} Then a caret. Put that all together: irb> re = %r{\A%B(\d{16})\^([^/]*)/([^ ^]*)(?: ([^ ^]))?\^} => /\A%B(\d{16})\^([^\/]*)\/([^ ^]*)(?: ([^ ^]))?\^/ irb> card_data = '%B6007503004905860^GEVIMSEDO/JRPN P^894212333300?; 604750230190488515=993612044400050600?+E?' => "%B6007503004905860^GEVIMSEDO/JRPN P^894212333300?; 604750230190488515=993612044400050600?+E?" irb> iso, last_name, first_name, middle_name = re.match(card_data).captures => ["6007503004905860", "GEVIMSEDO", "JRPN", "P"] irb> p iso, last_name, first_name, middle_name "6007503004905860" "GEVIMSEDO" "JRPN" "P" => nil -Rob Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com