Given an array of strings,
array1 = ["abcdwillbegoneabcccc","cdefwilbegokkkabcdc"]
and another array of strings which consist of patterns e.g. ["abcd","beg[o|p]n","bcc","cdef","h*gxwy"]
the task is to remove substrings that match any of the pattern strings. for example a sample output for this case should be:
["willbegonea","wilbegokkk"]
because we have removed the substrings (prematch or postmatch as is appropriate depending on the position of occurrence) that matched one of the patterns. Assume that the one or two matches will always occur at the beginning or towards the end of each string in array1.
Any ideas of an elegant solution to the above in ruby?
['willeacc', 'wilbegokkkc']. Also, your specification is incomplete: what should the result of['beabcdefgonx']be, given your patterns?['bdefgonx'],['beabgonx'],['begonx']or['x']? All of these are valid under some interpretation of your rules. As a general hint: whenever someone asks such a question on SO, they should supply an acceptance test suite with it. That makes it way easier to answer and shows that the poster actually put some genuine effort into the question.