Character string matching method and device, electronic equipment, storage medium and program product

By comparing the corresponding characters of the string to be matched and the search string and updating the matching position, effective and fast matching of the string to be matched and the search string is achieved, and the string matching problem that is difficult to achieve in the prior art is solved.

CN119884433APending Publication Date: 2025-04-25SHANGHAI DAMENG DATABASE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411934670.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

How to effectively and quickly match the string to be matched with the search string, especially when matching each character in the string.

Method used

By comparing the first character in the string to be matched with the second character in the search string, update the matching position until all characters in the search string traversal are completed, the matching result is obtained.

Benefits of technology

It realizes effective and fast matching retrieval of matching strings and search strings, and solves the problem of matching based on each character in the string.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884433A_ABST
    Figure CN119884433A_ABST
Patent Text Reader

Abstract

The invention discloses a character string matching method and device, electronic equipment and a storage medium. The method specifically comprises the steps of comparing a first character in a to-be-matched character string with a second character in a search character string, and updating the first character and the second character under the condition that the first character and the second character are successfully matched; under the condition that the matching of the first character and the second character fails, determining a first character comparison position in the to-be-matched character string, determining a second character comparison position in the search character string, and when a corresponding character exists at the first character comparison position, taking the character at the first character comparison position as an updated first character, and taking the character at the second character comparison position as an updated second character, and returning to continuously determine the comparison result until all characters in the search character string are traversed to obtain a matching result. According to the invention, effective and rapid matching retrieval of the to-be-matched character string and the search character string is realized, and the function of performing character string matching according to limited characters is completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a string matching method, device, electronic equipment, storage medium and program product. Background Art

[0002] Many applications have a large amount of string data in a specific format. Each string data is a multi-word combination in camel case format or a multi-word combination with characters such as space, underscore, and hyphen as word separators.

[0003] For multi-word string, people usually have a better impression of the first few characters of each word, and are more inclined to use the first characters of a word as abbreviated search terms. Therefore, how to find a string is a problem that needs to be solved at present. Summary of the invention

[0004] The present invention provides a string matching method, device, electronic device, storage medium and program product to solve the problem of string matching between a to-be-matched string and a search string.

[0005] According to one aspect of the present invention, there is provided a string matching method, comprising:

[0006] Comparing a first character in a to-be-matched string with a second character in a search string to determine a comparison result, wherein the to-be-matched string includes a string composed of at least one word;

[0007] If the comparison result indicates that the first character and the second character match successfully, updating the first character in the to-be-matched character string and the second character in the search character string;

[0008] If the comparison result indicates that the first character and the second character fail to match, determining a first character comparison position in the to-be-matched string, and determining a second character comparison position in the search string, the first character comparison position being a position determined according to a configuration of a separator in the to-be-matched string;

[0009] When there is a corresponding character at the first character comparison position, the character at the first character comparison position is used as the updated first character, and the character at the second character comparison position is used as the updated second character, and the comparison result is returned to continue to be determined until all characters in the search string are traversed and a matching result is obtained.

[0010] According to another aspect of the present invention, there is provided a string matching device, comprising:

[0011] A comparison module, used for comparing a first character in a to-be-matched string with a second character in a search string, and determining a comparison result, wherein the to-be-matched string includes a string composed of at least one word;

[0012] An updating module, configured to update the first character in the to-be-matched character string and the second character in the search character string if the comparison result indicates that the first character and the second character match successfully;

[0013] a determination module, configured to determine a first character comparison position in the to-be-matched string and a second character comparison position in the search string when the comparison result indicates that the first character and the second character fail to match, wherein the first character comparison position is a position determined according to a configuration of a separator in the to-be-matched string;

[0014] A traversal module is used to use the character at the first character comparison position as the updated first character and the character at the second character comparison position as the updated second character when there is a corresponding character at the first character comparison position, and return to continue determining the comparison result until all characters in the search string are traversed and a matching result is obtained.

[0015] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:

[0016] at least one processor; and

[0017] a memory communicatively connected to the at least one processor; wherein,

[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the string matching method described in any embodiment of the present invention.

[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the string matching method described in any embodiment of the present invention when executed.

[0020] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the string matching method described in any embodiment of the present invention is implemented.

[0021] The technical solution of the embodiment of the present invention is to determine the comparison result by comparing the first character in the string to be matched with the second character in the search string; if the comparison result indicates that the first character and the second character match successfully, update the first character in the string to be matched and the second character in the search string; if the comparison result indicates that the first character and the second character match unsuccessfully, determine the comparison position of the first character in the string to be matched, and determine the comparison position of the second character in the search string; if there is a corresponding character at the comparison position of the first character, use the character at the comparison position of the first character as the updated first character, use the character at the comparison position of the second character as the updated second character, and return to continue to determine the comparison result until all characters in the search string are traversed to obtain a matching result. By comparing the string to be matched with the search string to obtain the matching result, the problem of matching according to each character in the string is solved, and an effective and fast matching retrieval of the string to be matched and the search string is realized, and the function of matching strings according to limited characters is completed.

[0022] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 is a flowchart of a string matching method provided according to Embodiment 1 of the present invention;

[0025] Figure 2 is a flowchart of a word segmentation matching method provided according to Embodiment 1 of the present invention;

[0026] Figure 3 is a flow chart of a full-word matching method provided according to Embodiment 1 of the present invention;

[0027] Figure 4 is a flow chart of a method for determining a first character comparison position provided according to Embodiment 2 of the present invention;

[0028] Figure 5 is a flowchart of a positioning method provided according to Embodiment 2 of the present invention;

[0029] Figure 6 is a schematic diagram of the structure of a string matching device provided according to Embodiment 3 of the present invention;

[0030] Figure 7 It is a block diagram of an electronic device provided according to a fourth embodiment of the present invention. DETAILED DESCRIPTION

[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0033] Embodiment 1

[0034] Figure 1 A flowchart of a string matching method is provided for the first embodiment of the present invention. This embodiment is applicable to the case where a string to be matched is matched with a search string. The method can be used to match and retrieve a string, that is, input a search string, traverse the string to be matched, and obtain a successfully matched string to be matched. The method can be executed by a string matching device, which can be implemented in the form of hardware and / or software, and can be configured in an electronic device, which can be a mobile terminal, a PC, or a server, etc. Figure 1 As shown, the method includes:

[0035] S110: Compare a first character in a to-be-matched string with a second character in a search string to determine a comparison result, wherein the to-be-matched string includes a string composed of at least one word.

[0036] In this embodiment, the string to be matched can be understood as a multi-word combination composed of at least one word that can be used for string matching. The string to be matched can be a multi-word combination in camel case format, or a multi-word combination with characters such as space, underscore, and dash as word separators. The first character can be understood as a single character selected from the string to be matched. Table 1 shows a plurality of multi-word combinations in specific formats:

[0037] Table 1 Multi-word combinations in specific formats

[0038] File system - file name Program Code - Function Database - sql Bug-a1111-20250101.doc NullPointerException create table test.t1 Bug-b1111-30250101.doc DateTimeParseException update test.t1 set Bug-a2111-30250101.doc FileSystemNotFoundException delete from test.t1 where

[0039] Camel case is a common naming convention for naming variables and functions in programming. In camel case, the first letter of each word is capitalized, the rest of the letters are lowercase, and no separators (such as spaces, underscores, etc.) are used. Separators can be understood as identifiers used to combine multiple words in the string to be matched. A string to be matched can contain multiple and / or multiple separators. For example, the string to be matched "Bug-a2111_30250101.doc" contains three separators: '-', '_', and '.'.

[0040] The search string can be understood as a search term that can be used for string matching, and the search string can be used to filter and retrieve the string to be matched. The second character can be understood as a single character selected from the search string.

[0041] Specifically, the to-be-matched string and the search string are obtained after removing all leading and trailing spaces, and their lengths are determined respectively. When the length of the to-be-matched string is greater than the length of the search string, string matching is performed. The first character in the to-be-matched string and the second character in the search string are determined, and it is determined whether the first character and the second character are the same character, and a comparison result is determined.

[0042] Exemplarily, the string to be matched cmpStr can be a string composed of multiple words, such as: desc__scanner or executeCommand. The search string patternStr can be "de_sc" or "exe com". First, determine the length of the string to be matched [1, cmpLen], and the first character cmpStr(i), where i represents the position of the first character in the string to be matched. Similarly, determine the length of the search string [1, patternLen], and the second character patternStr(j), where j represents the position of the second character in the search string.

[0043] S120: When the comparison result indicates that the first character and the second character match successfully, update the first character in the to-be-matched character string and the second character in the search character string.

[0044] Specifically, when the comparison result indicates that the first character and the second character match successfully, the first character in the to-be-matched string and the second character in the search string are sequentially moved backward to obtain updated first and second characters. The updated first character in the to-be-matched string and the second character in the search string are continuously compared, and new first and second characters are determined according to the comparison result.

[0045] For example, Figure 2 1 is a flowchart of a word segmentation matching method provided according to the first embodiment of the present invention. Word segmentation matching can be understood as the operation of matching the to-be-matched string with the search string according to characters. Figure 2 As shown, the first character cmpStr(i) and the second character patternStr(j) are matched. If the match is successful, it is determined whether the second character is the last character, that is, whether j is patternLen. If so, the match is terminated and the result of successful match is output; if not, the next first character and second character are obtained, that is, i=i+1, j=j+1, and the match is continued.

[0046] S130. When the comparison result indicates that the first character and the second character fail to match, determine a first character comparison position in the string to be matched, and determine a second character comparison position in the search string, wherein the first character comparison position is a position determined according to a configuration of a separator in the string to be matched.

[0047] In this embodiment, the first character comparison position can be understood as a position determined according to the separator in the string to be matched, and the character at the first character comparison position can be further compared with the character in the search string. The second character comparison position can be understood as a position related to a space in the search string, and the character at the second character comparison position can be further compared with the character in the string to be matched.

[0048] Specifically, when the comparison result indicates that the first character and the second character match successfully, the next first character is obtained and compared with the second character. When the comparison result indicates that the first character and the second character fail to match, the first character comparison position is determined according to the separator in the string to be matched. The determination method can be to determine the first character comparison position by judging whether there are multiple consecutive identical separators and whether the separators are uppercase letters; and at the same time, determine the second character comparison position according to whether there are spaces in the search string and the number of spaces.

[0049] For example, Figure 2 As shown, in the case of a match failure, the comparison position of the first character and the second character is moved, and the comparison position of the first character can be determined by the situation of the separator in the string to be matched, that is, Figure 2 The positioning module is used to update i to the next M point position of the string to be matched, such as the type and number of delimiters; at the same time, the second character comparison position is determined by the configuration of the space in the search string. The M point can be the next starting comparison character of the string to be matched when the character comparison between the string to be matched and the search string fails, that is, the comparison anchor point, referred to as the M point. The M point is the next delimiter or the first letter of the next word of the current matching failure position of the string to be matched.

[0050] S140. When a corresponding character exists at the first character comparison position, the character at the first character comparison position is used as the updated first character, the character at the second character comparison position is used as the updated second character, and the comparison result is continued to be determined until all characters in the search string are traversed and a matching result is obtained.

[0051] Specifically, when the traversal of the string to be matched has been completed, there may be a situation where there is no corresponding character at the first character comparison position, and at this time, the matching result can be directly output as a match failure. When the corresponding character appears at the first character comparison position, the character at the first character comparison position can be used as the updated first character, and the character at the second character comparison position can be used as the updated second character. The first character and the second character are returned and continued to be matched until all characters in the search string are compared, that is, the position of the second character is the last position of the search string, the matching of the string to be matched and the search string is completed, and the matching result is output.

[0052] For example, Figure 2 , when the value of i at the first character comparison position is -1, there is no corresponding character at the first character comparison position, and the matching result indicates that the match failed. Otherwise, the character at the first character comparison position is used as the updated first character, and the character at the second character comparison position is used as the updated second character. Return to continue matching until the value of j is patternLen, then the matching ends and the matching result is output.

[0053] The technical solution of the embodiment of the present invention is to determine the comparison result by comparing the first character in the string to be matched with the second character in the search string; if the comparison result indicates that the first character and the second character match successfully, update the first character in the string to be matched and the second character in the search string; if the comparison result indicates that the first character and the second character match unsuccessfully, determine the comparison position of the first character in the string to be matched, and determine the comparison position of the second character in the search string; if there is a corresponding character at the comparison position of the first character, use the character at the comparison position of the first character as the updated first character, use the character at the comparison position of the second character as the updated second character, and return to continue to determine the comparison result until all characters in the search string are traversed to obtain a matching result. By comparing the string to be matched with the search string to obtain the matching result, the problem of matching according to each character in the string is solved, and an effective and fast matching retrieval of the string to be matched and the search string is realized, and the function of matching strings according to limited characters is completed.

[0054] Based on the above embodiment, a variant embodiment of the above embodiment is proposed. It should be noted that in order to make the description concise, only the differences from the above embodiment are described in the variant embodiment.

[0055] In one embodiment, determining the comparison position of the second character in the search string includes:

[0056] The first non-space character position after the second character in the search string is determined as the second character comparison position.

[0057] Specifically, determine whether there is a space in the search string. Spaces can interrupt continuous matching for string matching. If there is, the second character comparison position is the first character position after the space. If there are multiple consecutive spaces in the search string, the second character comparison position is the position of the first non-space character after the last space.

[0058] For example, if patternStr(j) is a space, let j move to the first non-space character position as the second character comparison position. For example, when patternStr=exe com, because patternStr(4) == '' is a space character, patternStr(5) == '' is also a space character, so let j=6, move to the first non-space character position, and the position of j=6 is the second character comparison position.

[0059] In one embodiment, the to-be-matched string and the search string are strings for which full-word matching fails, and the full-word matching operation includes:

[0060] Remove the spaces at the beginning and the end of the to-be-matched string and the search string to obtain an updated to-be-matched string and an updated search string;

[0061] In the case where the length of the updated to-be-matched string is greater than the length of the updated search string, the updated search string is taken as a whole, and if the updated to-be-matched string completely contains the updated search string, it is determined that the to-be-matched string and the search string are fully matched;

[0062] In the case where the length of the updated string to be matched is less than the length of the updated search string, or in the case where the length of the updated string to be matched is equal to the length of the updated search string and the updated string to be matched is not equal to the updated search string, it is determined that the full-word match between the string to be matched and the search string fails.

[0063] In this embodiment, the whole word match can be understood as an operation of matching the search string as a whole with the string to be matched.

[0064] Specifically, first remove the spaces at the beginning and end of the obtained string to be matched and the search string, that is, ensure that the first and last positions of the string to be matched and the search string are not space characters, obtain the updated string to be matched and the updated search string, and obtain the lengths of the updated string to be matched and the updated search string. In the case where the length of the updated string to be matched is greater than the length of the updated search string, the updated search string is taken as a whole. If the updated string to be matched completely contains the updated search string, the matching result indicates that the whole word match is successful; otherwise, enter the word segmentation match, and determine the string matching result based on the word segmentation match. In the case where the length of the updated string to be matched is less than the length of the updated search string, or the length of the updated string to be matched is equal to the length of the updated search string but the two are not equal, the matching result indicates that the whole word match fails, and the string matching fails.

[0065] For example, Figure 3 1 is a flowchart of a full-word matching method provided according to the first embodiment of the present invention. Determine the to-be-matched string cmpStr and the search string patternStr, remove all spaces at the beginning and end of cmpStr and patternStr, and obtain the updated to-be-matched string cmpStr and the updated search string patternStr. Determine the length of cmpStr as cmpLen, the length of patternStr as patternLen, such as Figure 3, when cmpLen > patternLen, the updated search string is taken as a whole. If the string to be matched contains the search string then the whole-word match is successful, that is, the string match is successful, and the matching ends; otherwise, the word segmentation matching is entered, and the matching result is determined according to the word segmentation matching. When cmpLen < patternLen, or cmpLen == patternLen and cmpStr != patternStr, the whole-word match fails and the matching ends.

[0066] Embodiment 2

[0067] Figure 4 The figure is a flowchart of a method for determining the first character comparison position provided by Embodiment 2 of the present invention. In this embodiment, the method for determining the first character comparison position in the above embodiment is elaborated. As Figure 4 shown, the method includes:

[0068] S210. Determine whether the first character is the last character in the string to be matched.

[0069] Specifically, when the comparison result indicates that the first character and the second character do not match, it is necessary to determine the first character comparison position. First, determine whether the currently compared first character is the last character in the string to be matched.

[0070] Exemplarily, Figure 5 is a flowchart of a positioning method provided by Embodiment 2 of the present invention. The range of the string to be matched cmpStr is [1, cmpLen]. When the first character cmpStr(i) and the second character patternStr(j) do not match, as Figure 5 shown, determine whether i is cmpLen at this time.

[0071] S220. If so, set the first character comparison position to a set value, and there is no corresponding character at the first character comparison position.

[0072] In this embodiment, the set value can be understood as a value indicating that the first character is the last character in the string to be matched, and the set value needs to be set to a value different from the value representing the position of the string to be matched.

[0073] Specifically, when the first character is the last character in the string to be matched, it means that the traversal of the string to be matched has ended. Set the first character comparison position to the set value, and there is no corresponding character at the first character comparison position at this time.

[0074] Exemplarily, as Figure 5, the setting value can be set to -1. When i is the position cmpLen of the last character of the string to be matched, the first character comparison position is set to -1 to end the positioning.

[0075] S230: If not, determine the comparison position of the first character according to whether the character following the first character is a separator.

[0076] Specifically, when the first character is not the last character of the string to be matched, the character after the first character is determined. If the character after the first character is a separator, the comparison position of the first character is determined according to the number of separators. If the character after the first character is not a separator, it is determined whether the first character is a separator and the comparison position of the first character is determined.

[0077] For example, when i!=cmpLen, let i=i+1, and determine whether cmpStr(i) is a separator. If so, determine the first character comparison position according to the number of separators; otherwise, determine the first character comparison position according to whether cmpStr(i-1) is a separator.

[0078] The technical solution of the embodiment of the present invention determines whether the first character is the last character in the string to be matched; if so, sets the first character comparison position to a set value, and there is no corresponding character at the first character comparison position; if not, determines the first character comparison position based on whether the character after the first character is a separator. By determining whether the first character is the last character in the string to be matched, the first character comparison position is determined, and the method of determining the first character comparison position based on a set value, a separator, etc. is refined.

[0079] Based on the above embodiment, a variant embodiment of the above embodiment is proposed. It should be noted that in order to make the description concise, only the differences from the above embodiment are described in the variant embodiment.

[0080] In one embodiment, determining the comparison position of the first character according to whether the character following the first character is a separator includes:

[0081] If the character following the first character is a separator, determine the number of consecutive identical separators from the character following the first character to the end of the string to be matched, and determine the comparison position of the first character based on the number of consecutive identical separators; otherwise, determine the comparison position of the first character based on whether the first character is a separator.

[0082] Specifically, if the character after the first character is a delimiter, determine whether there is a delimiter that is continuous and identical to the delimiter from the delimiter to the end of the string to be matched. If so, determine the first character comparison position according to the number of consecutive identical delimiters; if not, return to determine the first character comparison position according to the character after the first character. If the character after the first character is not a delimiter, determine whether the first character is a delimiter. If so, directly determine the first character comparison position; if not, determine the first character comparison position according to whether the first character and the character after the first character are uppercase letters.

[0083] For example, Figure 5 , first determine whether the character after the first character cmpStr(i) is a separator. If so, determine the number of consecutive identical separators n in the string to be matched cmpStr starting from i, and determine the first character comparison position according to the value of n. If not, determine the first character comparison position according to whether the first character cmpStr(i-1) is a separator.

[0084] In one embodiment, determining the first character comparison position according to the number of consecutive identical separators includes:

[0085] If the number of the consecutive identical delimiters is greater than 1, the position of the last delimiter in the consecutive identical delimiters is determined as the first character comparison position; otherwise, return to determine whether the character after the first character is the last character in the character string to be matched.

[0086] Specifically, when the character after the first character is a delimiter, determine the delimiters that are consecutively identical to the delimiter from the delimiter to the end of the string to be matched, as well as the number of delimiters. When the number of delimiters is greater than 1, the position of the last delimiter among the consecutive identical delimiters is determined as the first character comparison position, and the first character comparison position is returned; when the number of delimiters is 1, return to continue to determine, taking the character after the first character at this time as the first character, and determine whether the first character is the last character in the string to be matched. If so, set the first character comparison position to the set value, otherwise continue to determine the first character comparison position according to whether the character after the first character is a delimiter.

[0087] For example, Figure 5, when the character after the first character cmpStr(i) is a delimiter, determine the number n of consecutive identical delimiters starting from i in the to-be-matched string cmpStr. When n>1, there are consecutive identical delimiters, let i=i+n-1, locate i to the last consecutive identical delimiter, and use i as the first character comparison position; when n==1, there are no consecutive identical delimiters, and return to continue judging.

[0088] In one embodiment, determining the first character comparison position according to whether the first character is a separator includes:

[0089] If the first character is a separator, the position of the character following the first character is determined as the first character comparison position; otherwise, whether the character following the first character is an uppercase letter and the first character is not an uppercase letter is determined;

[0090] If so, the position of the character following the first character is determined as the first character comparison position; otherwise, return to determine whether the character following the first character is the last character in the character string to be matched.

[0091] Specifically, for characters to be matched that are consecutively capitalized, the first capitalized letter is the camel case of the characters to be matched. When the character after the first character is not a separator, determine whether the first character is a separator. If so, it is considered that the character after the first character is the first letter of the word after the separator in the string to be matched, then the position of the character after the first character is directly determined as the first character comparison position, and the first character comparison position is returned. If not, the first character comparison position is determined according to whether the first character and the character after the first character are capitalized: when the character after the first character is a capitalized letter and the first character is not a capitalized letter, the position of the character after the first character is determined as the first character comparison position; otherwise, return to continue to determine, take the character after the first character at this time as the first character, and determine whether the first character is the last character in the string to be matched. If so, set the first character comparison position to the set value, otherwise continue to determine the first character comparison position according to whether the character after the first character is a separator.

[0092] Exemplarily, if the first character cmpStr(i-1) is a separator, i is determined as the first character comparison position and returned. If the first character cmpStr(i-1) is not a separator, when cmpStr(i) is an uppercase letter and cmpStr(i-1) is not an uppercase letter, i is determined as the first character comparison position and returned; otherwise, it returns to continue judging. Table 2 shows some examples of string matching between the to-be-matched string and the search string. In the matching result column, the bold characters are matching characters:

[0093] Table 2 String matching examples

[0094]

[0095]

[0096] Exemplarily, the character string determination method provided by the embodiment of the present invention includes the following examples:

[0097] Example 1:

[0098] Step 1, define the string to be matched cmpStr=desc__scanner, the search string patternStr=de_sc, the separators are separators={'_'}, the length of the string to be matched cmpLen=13, and the length of the search string patternLen=5.

[0099] Step 2: Because the length of the to-be-matched string cmpLen is greater than the length of the search string patternLen, and the to-be-matched string cmpStr does not contain the search string patternStr, the full-word match fails, and the process enters word segmentation matching, and sets i=1, j=1.

[0100] Step 3, the string to be matched cmpStr(1) = 'd', the search string patternStr(1) = 'd', because the string to be matched cmpStr(i) is equal to the search string patternStr(j), and j is not equal to the length of the search string patternLen, so i = i+1 = 2, j = j+1 = 2; the string to be matched cmpStr(2) = 'e', ​​the search string patternStr(2) = 'e', ​​because the string to be matched cmpStr(i) is equal to the search string patternStr(j), and j is not equal to the length of the search string patternLen, so i = i+1 = 3, j = j+1 = 3; the string to be matched cmpStr(3) = 's', the search string patternStr(3) = '_', then the string to be matched cmpStr(i) is not equal to the search string patternStr(j).

[0101] Step 4, search string patternStr(3) is not equal to space, j remains unchanged at 3, enter the positioning module to find the first character comparison position; because i is not equal to the length cmpLen of the string to be matched, i=i+1=4, and the string to be matched cmpStr(4)='c' is not a separator; and because the string to be matched cmpStr(3)='s' is not a separator, and the string to be matched cmpStr(4) is not an uppercase letter; because i is not equal to the length cmpLen of the string to be matched, i=i+1=5, because the string to be matched cmpStr(5)='_' is a separator; because the string to be matched cmpStr(5) is not a single separator, there are n=2 consecutive identical separators '_' starting from the string to be matched cmpStr(5), so i=i+n-1=6, and finally return i=6.

[0102] Step 5, the string to be matched cmpStr(6) = '_', the search string patternStr(3) = '_', then the string to be matched cmpStr(i) is equal to the search string patternStr(j); because j is not equal to the length of the search string patternLen, i = i+1 = 7, j = j+1 = 4; the string to be matched cmpStr(7) = 's', the search string patternStr(4) = 's', then the string to be matched cmpStr(i) is equal to the search string patternStr(j); because j is not equal to the length of the search string patternLen, i = i+1 = 8, j = j+1 = 5; the string to be matched cmpStr(8) = 'c', the search string patternStr(5) = 'c', then the string to be matched cmpStr(i) is equal to the search string patternStr(j).

[0103] Step 6: Since j is equal to the length of the search string patternLen, the match is successful and the matching ends.

[0104] Example 2:

[0105] Step 1: There is a string to be matched cmpStr=executeCommand, a search string patternStr=exe com, separators are separators={} (space characters), the length of the string to be matched cmpLen=14, and the length of the search string patternLen=8.

[0106] Step 2: Because the length of the to-be-matched string cmpLen is greater than the length of the search string patternLen, and the to-be-matched string cmpStr does not contain the search string patternStr, the full-word match fails, and the process enters word segmentation matching, and sets i=1, j=1.

[0107] Step 3, the string to be matched cmpStr(1) = 'e', ​​the search string patternStr(1) = 'e', ​​because the string to be matched cmpStr(i) is equal to the search string patternStr(j), and j is not equal to the length of the search string patternLen, so i = i+1 = 2, j = j+1 = 2; the string to be matched cmpStr(2) = 'x', the search string patternStr(2) = 'x', because the string to be matched cmpStr(i) is equal to the search string patternStr(j), and j is not equal to the length of the search string patternLen en, so i=i+1=3, j=j+1=3; the string to be matched cmpStr(3)='e', the search string patternStr(3)='e', because the string to be matched cmpStr(i) is equal to the search string patternStr(j), and j is not equal to the length of the search string patternLen, so i=i+1=4, j=j+1=4; the string to be matched cmpStr(4)='c', the search string patternStr(4)='' (space character), the string to be matched cmpStr(i) is not equal to the search string patternStr(j).

[0108] Step 4, because the search string patternStr(4) is equal to '' (space character), j=6, and move to the first non-space character position; enter the positioning module to find the first character comparison position; because i is not equal to the length of the string to be matched cmpLen, i=i+1=5, and the string to be matched cmpStr(5)='u' is not a separator; because the string to be matched cmpStr(4)='c' is not a separator, and the string to be matched cmpStr(5) is not an uppercase letter; because i is not equal to the length of the string to be matched cmpLen, i=i+1=6, and the string to be matched cmpStr(6)='t' is not a separator; because the string to be matched cmpStr(5)='u' is not a separator, and The string to be matched cmpStr(6) is not an uppercase letter; because i is not equal to the length cmpLen of the string to be matched, i=i+1=7, and the string to be matched cmpStr(7)='e' is not a separator; because the string to be matched cmpStr(6)='t' is not a separator, and the string to be matched cmpStr(7) is not an uppercase letter; because i is not equal to the length cmpLen of the string to be matched, i=i+1=8, and the string to be matched cmpStr(8)='C' is not a separator; because the string to be matched cmpStr(7)='e' is not a separator, because the string to be matched cmpStr(8) is an uppercase letter and the string to be matched cmpStr(7) is not an uppercase letter, i=8 is returned.

[0109] Step 5, the string to be matched cmpStr(8) = 'C', the search string patternStr(6) = 'c', then the string to be matched cmpStr(i) is equal to the search string patternStr(j); because j is not equal to the length of the search string patternLen, i = i+1 = 9, j = j+1 = 7; the string to be matched cmpStr(9) = 'o', the search string patternStr(7) = 'o', then the string to be matched cmpStr(i) is equal to the search string patternStr(j); because j is not equal to the length of the search string patternLen, i = i+1 = 10, j = j+1 = 8; the string to be matched cmpStr(10) = 'm', the search string patternStr(8) = 'm', then the string to be matched cmpStr(i) is equal to the search string patternStr(j).

[0110] Step 6: Since j is equal to the length of the search string patternLen, the match is successful and the matching ends.

[0111] Embodiment 3

[0112] Figure 6 This is a schematic diagram of the structure of a string matching device provided in Embodiment 3 of the present invention. Figure 6 As shown, the device comprises:

[0113] A comparison module 310, configured to compare a first character in a to-be-matched string with a second character in a search string to determine a comparison result, wherein the to-be-matched string includes a string composed of at least one word;

[0114] An updating module 320, configured to update the first character in the to-be-matched character string and the second character in the search character string if the comparison result indicates that the first character and the second character match successfully;

[0115] A determination module 330, configured to determine a first character comparison position in the to-be-matched string and a second character comparison position in the search string when the comparison result indicates that the first character and the second character fail to match, wherein the first character comparison position is a position determined according to a configuration of a separator in the to-be-matched string;

[0116] The traversal module 340 is used to use the character at the first character comparison position as the updated first character and the character at the second character comparison position as the updated second character when there is a corresponding character at the first character comparison position, and return to continue to determine the comparison result until all characters in the search string are traversed and a matching result is obtained.

[0117] The string matching device provided by the embodiment of the present invention compares the first character in the string to be matched with the second character in the search string through a comparison module to determine the comparison result; updates the first character in the string to be matched and the second character in the search string through an update module when the comparison result indicates that the first character and the second character match successfully; determines the first character comparison position in the string to be matched and determines the second character comparison position in the search string when the comparison result indicates that the first character and the second character match unsuccessfully through a determination module; and uses the character at the first character comparison position as the updated first character and the character at the second character comparison position as the updated second character when there is a corresponding character at the first character comparison position through a traversal module, and returns to continue to determine the comparison result until all characters in the search string are traversed to obtain a matching result. Through the cooperation between the modules, the string to be matched and the search string are compared to obtain a matching result, which solves the problem of matching according to each character in the string, realizes effective and fast matching retrieval of the string to be matched and the search string, and completes the function of string matching according to limited characters.

[0118] In one embodiment, the determination module 320 is specifically configured to:

[0119] The first non-space character position after the second character in the search string is determined as the second character comparison position.

[0120] In one embodiment, the determination module 320 includes:

[0121] A first determining unit, used to determine whether the first character is the last character in the character string to be matched;

[0122] A setting unit, configured to set the first character comparison position to a set value if there is no corresponding character at the first character comparison position;

[0123] The second determining unit is configured to determine the comparison position of the first character according to whether the character following the first character is a separator.

[0124] In one embodiment, the second determining unit includes:

[0125] A determination subunit is used to determine the number of consecutive identical separators from the character following the first character to the end of the string to be matched if the character following the first character is a separator, and determine the comparison position of the first character according to the number of consecutive identical separators; otherwise, determine the comparison position of the first character according to whether the first character is a separator.

[0126] In one embodiment, the subunit is determined to be specifically configured to:

[0127] If the number of the consecutive identical delimiters is greater than 1, the position of the last delimiter in the consecutive identical delimiters is determined as the first character comparison position; otherwise, return to determine whether the character after the first character is the last character in the character string to be matched.

[0128] In one embodiment, the subunit is determined to be specifically configured to:

[0129] If the first character is a separator, the position of the character following the first character is determined as the first character comparison position; otherwise, whether the character following the first character is an uppercase letter and the first character is not an uppercase letter is determined;

[0130] If so, the position of the character following the first character is determined as the first character comparison position; otherwise, return to determine whether the character following the first character is the last character in the character string to be matched.

[0131] In one embodiment, the to-be-matched string and the search string are strings for which full-word matching fails, and the string matching device further includes a matching module, which is specifically used to:

[0132] Remove the spaces at the beginning and the end of the to-be-matched string and the search string to obtain an updated to-be-matched string and an updated search string;

[0133] In the case where the length of the updated to-be-matched string is greater than the length of the updated search string, the updated search string is taken as a whole, and if the updated to-be-matched string completely contains the updated search string, it is determined that the to-be-matched string and the search string are fully matched;

[0134] In the case where the length of the updated string to be matched is less than the length of the updated search string, or in the case where the length of the updated string to be matched is equal to the length of the updated search string and the updated string to be matched is not equal to the updated search string, it is determined that the full-word match between the string to be matched and the search string fails.

[0135] The string matching device provided in the embodiment of the present invention can execute the string matching method provided in any embodiment of the present invention, completes the string matching through the mutual cooperation and collaboration between the modules, and has the functional modules and beneficial effects corresponding to the execution method.

[0136] Embodiment 4

[0137] According to an embodiment of the present invention, the present invention also provides an electronic device, a computer-readable storage medium and a computer program product.

[0138] Figure 7 It is a block diagram of an electronic device provided according to Embodiment 4 of the present invention, and the electronic device can implement the string matching method described in the embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0139] like Figure 7 As shown, the electronic device 410 includes at least one processor 411, and a memory connected to the at least one processor 411 in communication, such as a read-only memory (ROM) 412, a random access memory (RAM) 413, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 411 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 412 or the computer program loaded from the storage unit 418 to the random access memory (RAM) 413. In the RAM 413, various programs and data required for the operation of the electronic device 410 can also be stored. The processor 411, the ROM 412, and the RAM 413 are connected to each other via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.

[0140] A number of components in the electronic device are connected to the I / O interface 415, including: an input unit 416, such as a keyboard, a mouse, etc.; an output unit 417, such as various types of displays, speakers, etc.; a storage unit 418, such as a disk, an optical disk, etc.; and a communication unit 419, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 419 allows the electronic device to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0141] Processor 411 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. Processor 411 performs the various methods and processes described above, such as a string matching method.

[0142] In some embodiments, the string matching method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 410 via the ROM 412 and / or the communication unit 419. When the computer program is loaded into the RAM 413 and executed by the processor 411, one or more steps of the string matching method described above may be performed. Alternatively, in other embodiments, the processor 411 may be configured to perform the string matching method in any other appropriate manner (e.g., by means of firmware).

[0143] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0144] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0145] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0146] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0147] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0148] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0149] In some embodiments, the computer program product includes a computer program, and when the computer program is executed by a processor, the string matching method provided by the embodiment of the present invention is implemented.

[0150] The technical solution of the embodiment of the present invention is to compare the first character in the string to be matched with the second character in the search string through a string matching method, device, electronic device, storage medium and program product, and determine the comparison result by comparing the first character in the string to be matched with the second character in the search string; if the comparison result indicates that the first character and the second character match successfully, update the first character in the string to be matched and the second character in the search string; if the comparison result indicates that the first character and the second character match unsuccessfully, determine the comparison position of the first character in the string to be matched, and determine the comparison position of the second character in the search string; if there is a corresponding character at the comparison position of the first character, use the character at the comparison position of the first character as the updated first character, use the character at the comparison position of the second character as the updated second character, and return to continue to determine the comparison result until all characters in the search string are traversed and a matching result is obtained. By comparing the string to be matched with the search string to obtain the matching result, the problem of matching according to each character in the string is solved, and an effective and fast matching retrieval of the string to be matched and the search string is realized, and the function of matching strings according to limited characters is completed.

[0151] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0152] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A string matching method, characterized in that: include: Comparing a first character in a to-be-matched string with a second character in a search string to determine a comparison result, wherein the to-be-matched string includes a string composed of at least one word; If the comparison result indicates that the first character and the second character match successfully, updating the first character in the to-be-matched character string and the second character in the search character string; If the comparison result indicates that the first character and the second character fail to match, determining a first character comparison position in the to-be-matched string, and determining a second character comparison position in the search string, the first character comparison position being a position determined according to a configuration of a separator in the to-be-matched string; When there is a corresponding character at the first character comparison position, the character at the first character comparison position is used as the updated first character, and the character at the second character comparison position is used as the updated second character, and the comparison result is returned to continue to be determined until all characters in the search string are traversed and a matching result is obtained.

2. The method according to claim 1, characterized in that: Determining the comparison position of the second character in the search string includes: The first non-space character position after the second character in the search string is determined as the second character comparison position.

3. The method according to claim 1, characterized in that Determining the first character comparison position in the to-be-matched string includes: Determine whether the first character is the last character in the string to be matched; If so, the first character comparison position is set to a set value, and there is no corresponding character at the first character comparison position; If not, the comparison position of the first character is determined according to whether the character following the first character is a separator.

4. The method according to claim 3, characterized in that: The determining the comparison position of the first character according to whether the character following the first character is a separator comprises: If the character following the first character is a separator, determine the number of consecutive identical separators from the character following the first character to the end of the string to be matched, and determine the comparison position of the first character based on the number of consecutive identical separators; otherwise, determine the comparison position of the first character based on whether the first character is a separator.

5. The method according to claim 4, characterized in that The determining the first character comparison position according to the number of consecutive identical delimiters includes: If the number of the consecutive identical delimiters is greater than 1, the position of the last delimiter in the consecutive identical delimiters is determined as the first character comparison position; otherwise, return to determine whether the character after the first character is the last character in the character string to be matched.

6. The method according to claim 4, characterized in that The determining the comparison position of the first character according to whether the first character is a separator includes: If the first character is a separator, the position of the character following the first character is determined as the first character comparison position; otherwise, whether the character following the first character is an uppercase letter and the first character is not an uppercase letter is determined; If so, the position of the character following the first character is determined as the first character comparison position; otherwise, return to determine whether the character following the first character is the last character in the character string to be matched.

7. The method according to claim 1, characterized in that The to-be-matched string and the search string are strings for which full-word matching fails, and the operation of full-word matching includes: Remove the spaces at the beginning and the end of the to-be-matched string and the search string to obtain an updated to-be-matched string and an updated search string; In the case where the length of the updated to-be-matched string is greater than the length of the updated search string, the updated search string is taken as a whole, and if the updated to-be-matched string completely contains the updated search string, it is determined that the to-be-matched string and the search string are fully matched; In the case where the length of the updated string to be matched is less than the length of the updated search string, or in the case where the length of the updated string to be matched is equal to the length of the updated search string and the updated string to be matched is not equal to the updated search string, it is determined that the full-word match between the string to be matched and the search string fails.

8. A string matching device, characterized in that: include: A comparison module, used for comparing a first character in a to-be-matched string with a second character in a search string, and determining a comparison result, wherein the to-be-matched string includes a string composed of at least one word; An updating module, configured to update the first character in the to-be-matched character string and the second character in the search character string if the comparison result indicates that the first character and the second character match successfully; a determination module, configured to determine a first character comparison position in the to-be-matched string and a second character comparison position in the search string when the comparison result indicates that the first character and the second character fail to match, wherein the first character comparison position is a position determined according to a configuration of a separator in the to-be-matched string; A traversal module is used to use the character at the first character comparison position as the updated first character and the character at the second character comparison position as the updated second character when there is a corresponding character at the first character comparison position, and return to continue determining the comparison result until all characters in the search string are traversed and a matching result is obtained.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the string matching method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the string matching method according to any one of claims 1 to 7 when executed.

11. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the computer program implements the string matching method according to any one of claims 1 to 7.