使用星号*通配符进行字符串搜索

时间:2021-10-02 20:06:50

I am looking to search a string for another shorter string which may contain wildcard characters * which match zero or more characters. For instance, if the main string is "Searching this string for a substring", and search string is "is*ing" should return a match at "is string". What is the algorithm to be used for this kind of search. Most algorithms present do globbing or pattern matching, but they don't do substring search.

我希望在字符串中搜索另一个较短的字符串,该字符串可能包含匹配零个或多个字符的通配符*。例如,如果主字符串是“正在搜索此字符串以查找子字符串”,并且搜索字符串为“is * ing”,则应返回“is string”处的匹配项。用于此类搜索的算法是什么?大多数算法都会进行通配或模式匹配,但它们不进行子串搜索。

1 个解决方案

#1


1  

Any good substring search algorithm (like KMP) shall serve your purpose.

任何好的子字符串搜索算法(如KMP)都将满足您的需求。

First search for the substring "is". Then once you found the substring, start searching for the string "ing" in the remaining part of the super-string.

首先搜索子串“是”。然后,一旦找到子字符串,就开始在超级字符串的剩余部分中搜索字符串“ing”。

Above technique shall work because you want to find a list of substrings in a particular sequence.

上述技术应该有效,因为您想要查找特定序列中的子串列表。

#1


1  

Any good substring search algorithm (like KMP) shall serve your purpose.

任何好的子字符串搜索算法(如KMP)都将满足您的需求。

First search for the substring "is". Then once you found the substring, start searching for the string "ing" in the remaining part of the super-string.

首先搜索子串“是”。然后,一旦找到子字符串,就开始在超级字符串的剩余部分中搜索字符串“ing”。

Above technique shall work because you want to find a list of substrings in a particular sequence.

上述技术应该有效,因为您想要查找特定序列中的子串列表。