Class WildKMPMatching

java.lang.Object
io.github.connellite.match.WildKMPMatching

public class WildKMPMatching extends Object
A modified version of the original Knuth-Morris-Pratt substring search algorithm which allows wildcards.
Author:
Varun Shah
  • Constructor Details

    • WildKMPMatching

      public WildKMPMatching()
  • Method Details

    • isMatch

      public static boolean isMatch(CharSequence text, CharSequence pattern)
      Each '*' matches exactly one character; consecutive '*' characters must match the same character in that run. A match is any window of text with length pattern.length() for which matchesWindow(CharSequence, int, CharSequence) is true.
      Parameters:
      text - source text; not null
      pattern - wildcard pattern; not null
      Returns:
      true when at least one match exists in text
    • search

      public static int search(CharSequence text, CharSequence pattern)
      Given some text and a pattern, it searches for the first instance of the pattern in the text.
      An asterisk (*) in the pattern tells the algorithm to match on any character at that location in the text.
      Parameters:
      text - The text to be searched
      pattern - The pattern to search for in the text
      Returns:
      The starting index of the pattern in the text. If not found, -1 is returned.