Question
I am trying to pull data from a file in ruby using regular expressions. I want to be able to ask the user for a
I am trying to pull data from a file in ruby using regular expressions. I want to be able to ask the user for a department and class number then print all of them from the file. I am using ATOM to try to do this and when I get it working I pull it from the file in RubyMine and it no longer works. If I can get it to pull the class file out I cannot get it to do so for the entire file. Only for the last line of the file. How can I get all for that department/class that the user enters using regular expressions?
This is what I have for my regular expression
^(\d{3}\s+|\s*)[A-Z0-9]{4}.([A-Z&]+)\s+(\d{3})\s+([A-Z0-9]{2,3})\s+([A-Z0-9]+)?(\d+)?\s+[A-Z0-9]{2}\s+([A-Z0-9+/:-^]+)?\s+([\D]+|\d+)?\s+(\d{1}\s+)?([A-Z]+\s+)?([A-Z]+\s+)?(\d+[.]\d|[.]\d)?\s+(\d+[.]\d|[.]\d)?\s+(([A-Za-z0-9]+\s+?|\s+)?([A-Z]+\s+|\s+)?(\d{3}\s+)?([0-9A-Z]+\s+)?([A-Z]+\s+)?(\d+[:]\d+[AP]\s+|[ARR]+\s+)?(\d+[:]\d+[AP]\s+|[ARR]+\s+) (\d+\s+|\d+\D\s+|\D\s+)(\d+\s+)?(\d+\s+)(\d+[.]\d|[.]\d)?)?
This is the text file I am trying to pull from. I only want the lines for each class (and additional lines for that class if they exist) not any of the header data or generic page data. Each class number starts with 3 or 4 digits, followed by the department, then the class number. I want to pull out the data by the department and class number the user entered. EX: ABF 243 . Would pull out
0516 ABF 243 AN CJ ADV UNIBODY 6.0 6.0 ChristensenE 018
0155 F 7:30A 8:30A 20 20 0 8.0
ChristensenE 018
0155 MTW 9:30A 10:30A
ChristensenE 018
0155 DAILY 8:30A 9:30A
The text file varies for each class so I need to account for all varying information. I essentially need all information until I get to the next class. Below are some file examples
717 3232 BIOL& 241 HN MB ANAT PHYSIOL .0 3.0 Cole D 027 0201 MWF 7:30A 8:30A 18 16 2 3.2 Class is closed, but enrollment has dropped below capacity Permission is required to register in this class 852 3237 BIOL& 260 A1 MB MICRO LAB 5.0 2.0 Bassett S 027 0206 TTh 11:30A 1:30P 24 24 0 3.2 Bassett S 027 0201 MWF
342 1728 BUS& 201 CN H3 BUS LAW 5.0 5.0 McLean J 798 ARRANGED ARR ARR 34 34 0 11.3 Online Class 798 ARRANGED ARR ARR
4197 BT 101 AW 4197 HC KEYBOARDING 5.0 5.0 Farrell J 001 1210 TTh 5:30P 8:00P 15^ 6 4 2.0 1761 BT 101 BN 1779 HC KEYBOARDING 5.0 5.0 Kennedy C 001 1210 DAILY 8:30A 9:30A 23^ 9 0 3.0 4200 BT 101 BW 4200 HC KEYBOARDING 5.0 5.0 Farrell J 001 1210 Sa 8:00A 12:30P 15^ 4 10 1.3 1764 BT 101 CN HC KEYBOARDING 5.0 5.0 Renner S 001 1115 DAILY 9:30A 10:30A 26 26 0 8.7 1767 BT 101 DN 1782 HC KEYBOARDING 5.0 5.0 Kennedy C 001 1210 DAILY 10:30A 11:30A 23^ 13 0 4.3 1770 BT 101 EN HC KEYBOARDING 5.0 5.0 Dunham L 001 1113F TThF 11:30A 12:30P 26 21 5 7.0 Dunham L 001 1220F W ARR Hybrid Class 001 1113F M ARR ARR 342 1773 BT 101 FN 1773 HC KEYBOARDING 5.0 5.0 Online Class 001 0229G ARRANGED ARR ARR Renner S 001 0229G ARRANGED ARR ARR 30^ 13 0 4.3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started