Given an input.txt
file like this:
Modified : /Analitics/Documents/HTZ/BR-5545 Credit/Example BR-5545.docx
Modified : /Analitics/Documents/HTZ/BR-5545 Credit/HTZ BR-5545 Example.docx
You could obtain what you want with this
File.open('input.txt').inject([]) do |array, line|
array << line.scan(/(BR-\d*)/)
end.flatten.uniq
Basically:
- we open the file
- we start injecting the result of the iteration into the
array
variable, which is initialized to[]
- we scan each line for the desired regexp
- after collecting all the results, we flatten it so that we have a one-dimensional array
- then we call uniq on it to remove duplicates