Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/evn ruby
- def parse_line remainder_of_line
- puts "Processing: #{remainder_of_line}"
- # Save a copy of the initial input for later comparison
- initial_snapshot = remainder_of_line.dup
- # Look for known pattern matches, removing them if found
- if remainder_of_line.gsub!(/^(d+) 0 -1 1 (d+) d+s*/, '')
- puts " - Matched format 1 - found: #{$1} - #{$2}nn"
- elsif remainder_of_line.gsub!(/^d+ 0 -1 2 (d+) d+s*/, '')
- puts " - Matched format 2 - found: #{$1}nn"
- ### More patterns here.
- end
- # If noting changed, then no matches were found.
- if initial_snapshot.eql? remainder_of_line
- puts " - Line still has data but no matches found. (Left with: #{remainder_of_line}nn"
- # Keep going if there is anything left.
- elsif !remainder_of_line.empty?
- parse_line remainder_of_line
- end
- end
- line = "11 0 -1 2 13560 2 11 0 -1 2 13564 2 11 0 -1 1 36880 106 91 0 -1 1 36881 106 36881 106 91 1 13556 2 36880 106 36880 106 11 1 734 11 0 -1 1 36884 106 91 0 -1 1 36885 106 36885 106 91 1 13556 2 36884 106 36884 106 11 1 735 13556 2 31 18 799 13556 2 31 25 799 "
- parse_line line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement