Class: Regexp

Inherits:
Object
  • Object
show all
Defined in:
lib/seqtrimnext/utils/global_match.rb

Instance Method Summary collapse

Instance Method Details

#global_match(input_str, overlap_group_no = 0) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/seqtrimnext/utils/global_match.rb', line 10

def global_match(input_str,overlap_group_no = 0)
  res = []
  
  str=input_str
  
  last_end = 0
  
  loop do
    str = input_str.slice(last_end,input_str.length-last_end)
    if str.nil? or str.empty?
      break
    end
    
    m = self.match(str)
    # puts "find in: #{str}"
    
    if !m.nil?
      # puts m.inspect
      
      
      new_match=GMatch.new()
      new_match.offset = last_end
      new_match.match = m
      
      res.push new_match
      
      if overlap_group_no == 0
        last_end += m.end(overlap_group_no)
      else
        last_end += m.begin(overlap_group_no)
      end
      
    else
      break
    end
    
  end
  
  
  return res
end