I am a newcomer in Ruby and I need help I have a sample part of .txt
Modified : /Analitics/Documents/HTZ/BR-5545 Credit/Example BR-5545.docx
Modified : /Analitics/Documents/HTZ/BR-5545 Credit/HTZ BR-5545 Example.docx
I need to find only digits in rows and only one time. (unique set of digits that appears only one time) With regexp I find digits
line=~/(BR-\d*)/
my=line.scan(/(BR-\d*)/)
Output:
`[["BR-5545"], ["BR-5545"]]`
But I need one time:
`[["BR-5545"]`
Please,help me how to transformate my regexp
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:
array
variable, which is initialized to []