Created
December 16, 2016 10:43
-
-
Save anonymous/d4f8bf6d9891ada3d5c10c402edfdb99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_with_regex *p_arr | |
raise ArgumentError if p_arr.length < 1 | |
result_s = self.dup | |
finds = p_arr.map do |rex| | |
result = {} | |
result_s.scan(rex) do | |
full_length = $&.length | |
start = $~.begin(0) | |
match = $~ | |
result[start..start+full_length] = $~ | |
end | |
result | |
end | |
intersection = Hash.new { |h,k| h[k] = [] } | |
finds.each_with_index do |h1,i1| | |
finds.each_with_index do |h2,i2| | |
if i1 < i2 | |
h1.each do |segment1,x| | |
h2.each do |segment2,y| | |
if segment1.include? segment2.begin | |
intersection[i2] << segment2 | |
end | |
end | |
end | |
end | |
end | |
end | |
intersection.each do |arr_idx,segments| | |
segments.each do |seg| | |
finds[arr_idx].delete(seg) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment