diff options
| author | mo <mokha@cisco.com> | 2017-08-09 16:22:59 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-09 16:22:59 -0600 |
| commit | e96dd6f704956291c99ff2495954fb31f07280cc (patch) | |
| tree | 455536e44979ef56573eab3c1765ffa7d5363e63 | |
| parent | 8a9b926699bcd0be39a27085efdc907963f9f51a (diff) | |
first attempt regex matching.
| -rw-r--r-- | spec/binary_trees/find_substrings_spec.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/binary_trees/find_substrings_spec.rb b/spec/binary_trees/find_substrings_spec.rb index 5b44b5d..60b7333 100644 --- a/spec/binary_trees/find_substrings_spec.rb +++ b/spec/binary_trees/find_substrings_spec.rb @@ -35,7 +35,18 @@ DOC describe "#find_substrings" do def find_substrings(words, parts) - words + regex = /(#{parts.join("|")})/ + puts regex.inspect + words.map do |word| + match = word.match(regex) + if match + max = match.captures.max { |a, b| a.length <=> b.length } + puts [word, match.captures, max].inspect + word.gsub(max, "[#{max}]") + else + word + end + end end [ |
