Example:
array1 = ["budget2017.doc", "accounting2017.doc", "mydogisdumb.doc"]
array2 = ["budget.doc", "accounting.doc", "imstupid.doc"]
I would like to compare the two arrays for similarity and return the associated element from array1.
array1.select { |x| x.include?(array2) }
I need the result to be a new array with ["budget2017.doc", "accounting2017.doc"]
But obviously the above won't work because "budget.doc" is not a match with "budget2017.doc". I could accomplish what I need if I could just match the first few characters of each element and return the associated element from array1.
=~operator (x1 =~ x2 iirc).mydogisdumb.docandimstupid.docshouldn't match then? Also the result that you gave us shows two elements fromarray1, not one fromarray1and one fromarray2, what is up with that? Also can you define "a few"? Is two enough? Is one enough?