array1 = [ "unit 1 : Unit 1" ,"unit 2 : Unit 2" ,"unit 3 : Unit 3" ,"test : Test" , "system1" ]
array2 = [ "unit 1" ,"unit 2" ,"unit 3" ,"test" ]
array1.each do | element|
#see if element exists in array 2
#if array2.include? element[/\A([^:]*?)\s*:/, 1]
if array2.include ? element.split ( ' : ' ) .first
#print the name of that element
puts element
end
end
puts array1.inspect
puts array2.inspect
YXJyYXkxID0gWyJ1bml0IDEgOiBVbml0IDEiLCJ1bml0IDIgOiBVbml0IDIiLCJ1bml0IDMgOiBVbml0IDMiLCJ0ZXN0IDogVGVzdCIsICJzeXN0ZW0xIl0KYXJyYXkyID0gWyJ1bml0IDEiLCJ1bml0IDIiLCJ1bml0IDMiLCJ0ZXN0Il0KYXJyYXkxLmVhY2ggZG8gfGVsZW1lbnR8CiAgICAjc2VlIGlmIGVsZW1lbnQgZXhpc3RzIGluIGFycmF5IDIKICAgICNpZiBhcnJheTIuaW5jbHVkZT8gZWxlbWVudFsvXEEoW146XSo/KVxzKjovLCAxXQogICAgaWYgYXJyYXkyLmluY2x1ZGU/IGVsZW1lbnQuc3BsaXQoJyA6ICcpLmZpcnN0CiAgICAgICAgICNwcmludCB0aGUgbmFtZSBvZiB0aGF0IGVsZW1lbnQKICAgICAgICAgcHV0cyBlbGVtZW50CiAgICBlbmQKZW5kCnB1dHMgYXJyYXkxLmluc3BlY3QKcHV0cyBhcnJheTIuaW5zcGVjdA==
stdout
unit 1 : Unit 1
unit 2 : Unit 2
unit 3 : Unit 3
test : Test
["unit 1 : Unit 1", "unit 2 : Unit 2", "unit 3 : Unit 3", "test : Test", "system1"]
["unit 1", "unit 2", "unit 3", "test"]