Class WordsTrie

java.lang.Object
com.cloudbees.jenkins.support.filter.WordsTrie

public class WordsTrie extends Object
Trie implementation to generate a "Trie regex". A regex that reduces backtracking by following a Trie structure.

When searching for a match within a list of words, for example ["go", "goes", "going", "gone", "goose"], a simple regex that matches any word would typically look like \b(?:(go|goes|going|gone|goose))\b.

While this works, Such a pattern can be optimized significantly by following a Trie structure in the prefixes such as \b(?:go(?:(?:es|ing|ne|ose))?)\b.

  • Constructor Details

    • WordsTrie

      public WordsTrie()
  • Method Details

    • add

      public void add(String word)
      Add a word to the Trie.
      Parameters:
      word - the word
    • getRegex

      public String getRegex()
      Get the regex String of this Trie.
      Returns:
      the regex String of this Trie.