lib/regxing/regex.rb in regxing-0.0.1.beta vs lib/regxing/regex.rb in regxing-0.1.0.beta
- old
+ new
@@ -28,10 +28,25 @@
/\[\[\:cntrl\:\]\]/ => "\a",
/\[\[\:upper\:\]\]/ => random_uppercase_letter
}
end
+ def count_indicators
+ [ /(?<!\\)\*/, /(?<!\\)\+/, /(?<!\\)\?/, /\{\d*\,?\d*\}/ ]
+ end
+
+ def process_count_indicator(indicator)
+ if indicator.match count_indicators.last
+
+ minimum = indicator.match(/(?<=\{)\d+/) ? indicator.match(/(?<=\{)\d+/)[0].to_i : 1
+
+ return minimum
+ else
+ return 1
+ end
+ end
+
private
def random_letter
("a".."z").to_a.sample
end
@@ -78,9 +93,19 @@
def to_s
expression.inspect[1..-2]
end
def split
- to_s.scan(/\\\?|[^\\]?\?|\\\.|[^\\]?\.|\\\+|[^\\]?\+|\\\*|[^\\]?\*|\\[a-zA-Z]|(?<!\\)[a-zA-Z]|\{\d*\,?\d*\}|\[\[\:.{5,6}\:\]\]|./).flatten
+ arr = to_s.scan(/\\\?|[^\\]?\?|\\\.|[^\\]?\.|\\\+|[^\\]?\+|\\\*|[^\\]?\*|\\[a-zA-Z]|(?<!\\)[a-zA-Z]|\{\d*\,?\d*\}|\[\[\:.{5,6}\:\]\]|./).flatten
+
+ arr.each_with_index do |item, index|
+ if RegXing::Regex.count_indicators.any? {|exp| arr[index + 1] && arr[index + 1].match(exp) }
+ arr[index] = [ item, RegXing::Regex.process_count_indicator(arr.delete_at(index + 1)) ]
+ else
+ arr[index] = [item, 1]
+ end
+ end
+
+ arr
end
end
end