From: Robert Klemme Date: 2006-08-12T19:35:14+09:00 Subject: Re: Regexp Parsing -- What's the right way? skelastic@gmail.com wrote: > Greetings, > > I'm trying to parse the following line: > > "00608 P 135 001 LEC Tu 2-5P 210 WHEELER Information Tech and Soceity > 3 LAGUERRE" > > i've constructed the following regexp: > /(\d{5}).(\D\s\w{2,4}).(\d{1,4}\s\D{3}).(\D{1,4}\s\d+).*(\d{1,4}\s\D{1,9}).(\w+).*(\d?).*(\w{1,14}).*/ > > with a input file i've successfully produced the following output: > control# 00608 ---- correct > course#: P 135 ---- correct > section#: 001 LEC ---- correct > day-hour#: Tu 2 ---- missing '-5P > room#: 3 LAGUERRE, ---- should be 210 WHEELER > course-name#: M --- IT and Soceity > credits#: --- should be 3 > prof#: 5 --- should be LAGUERRE > > i'm a novice to ruby and regexp. i would like to know if i'm taking > the right approach. > i'll eventually nail it but any hints or suggestions would be useful. > > appreciate the help. Looks pretty ok to me apart from that I'd use \s instead of . to parse white space separating entries. robert