I have a file that has sections like this,
flags...id, description, used, color
AB, "Abandoned", 0, 13168840
DM, "Demolished", 0, 15780518
OP, "Operational", 0, 15780518...
where ...
represents a series of control characters e.g. ETX and STX. I am trying to grab multiple lines from the file.
I am using the following code:
f = File.open(somePath)
r = f.grep(/flags.+id, description, used, color(?<data>(?:.|\s)*?)[\x00-\x08]/)
This code does not work. I do not understand why. The documentation of grep appears to insinuate that the file is parsed line by line. I have a feeling that this may be the reason why the regular expression isn't returning any results.
file.each_line
to capture the data?String#scan
comes to the rescue:
File.read('/path/to/file').scan(
/flags.+id, description, used, color(?<data>(?:.|\s)*?)[\x00-\x08]/m
)