Package io.github.connellite.match
Class WildKMPMatching
java.lang.Object
io.github.connellite.match.WildKMPMatching
A modified version of the original Knuth-Morris-Pratt substring search algorithm which allows wildcards.
- Author:
- Varun Shah
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisMatch(CharSequence text, CharSequence pattern) Each'*'matches exactly one character; consecutive'*'characters must match the same character in that run.static intsearch(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.
-
Constructor Details
-
WildKMPMatching
public WildKMPMatching()
-
-
Method Details
-
isMatch
Each'*'matches exactly one character; consecutive'*'characters must match the same character in that run. A match is any window oftextwith lengthpattern.length()for whichmatchesWindow(CharSequence, int, CharSequence)istrue.- Parameters:
text- source text; not nullpattern- wildcard pattern; not null- Returns:
truewhen at least one match exists intext
-
search
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 searchedpattern- The pattern to search for in the text- Returns:
- The starting index of the pattern in the text. If not found, -1 is returned.
-