=abstract A simple, non-regular expression pattern matching module mainly to perform file name pattern matching, like *.txt or file0?.bin and alikes. =end
This is a simple and fast pattern matching algorithm. This can be used when the matching does not require regular expression complexity and the processign on the other hand should be fast.
There are two major tasks implemented here. One is to match a string against a pattern. The second is to create a replacement string. When a pattern is matched by a string an array of string values are created. Each contains a substring that matches a joker character. Combining this array and a format string a replacement string can be created.
String = "mortal combat"
Pattern = "mo?tal co*"
String = "mortal combat" Pattern = "mo?tal co*"
the joker characters are the ?, the space (matching one or more space) and the * character. They are matched by r, two spaces and mbat. If we use the format string
Format string = "$1u$2"
we get the result string rumbat. The format string can contain $n placeholders where n starts with 1 and is replaced by the actual value of the n-th joker character.