Regular expression matching method and device, equipment, storage medium and program product

By extracting the string characteristics of the corpus to be matched, generating and compressing the state transition table, the problem of low efficiency of regular expression matching in the existing technology is solved, and fast and accurate matching effects are achieved in complex rule scenarios.

CN118796973APending Publication Date: 2024-10-18CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202311454895.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-01
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

Existing regular expression matching solutions have low matching efficiency in complex repetitive grammar scenarios, and lack optimization for different forms of grammar rules, making it difficult to show sufficient performance in efficient, multi-rule parallel matching scenarios.

Method used

Extract the target string from the corpus to be matched through the preset string set, generate a local state transfer table, dynamically compress based on the original NFA state transfer table, and merge to generate the target state transfer table to achieve fast regular expression matching.

Benefits of technology

It effectively reduces the runtime overhead of automata jumping to invalid states, greatly improves matching efficiency and accuracy, and can quickly and accurately implement regular expression matching in complex rule scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796973A_ABST
    Figure CN118796973A_ABST
Patent Text Reader

Abstract

The invention discloses a regular expression matching method and device, equipment, a storage medium and a program product, and relates to the technical field of Internet. The method comprises the steps of extracting N target character strings from a to-be-matched corpus based on a preset character string set; the preset character string set comprises N target character strings, and the preset character string set is determined based on an original non-deterministic finite automaton (NFA) state transition table in advance; the original NFA state transition table is constructed based on a regular expression set in advance; generating a target state transition table corresponding to the to-be-matched prediction based on the local state transition table corresponding to each target character string in the N target character strings; based on the target state transition table, performing regular expression matching on the to-be-matched corpus to obtain a regular expression matching result of the to-be-matched corpus; the local state transition table is obtained based on compression of the original NFA state transition table. According to the embodiment of the invention, regular expression matching can be realized more quickly and accurately.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of Internet technology, and in particular, relates to a regular expression matching method, device, equipment, storage medium and program product. Background Art

[0002] The existing rule matching technology for text search and network data flow is mainly based on the automaton engine technology of regular expressions, and its core theoretical basis is the equivalence principle of regular expressions and automata in formal language and automata theory. The mainstream implementation method is to parse the regular expression into an abstract syntax tree (AST) based on regular grammar, and then construct an NFA (Non-Deterministic Finite Automata) / DFA (Deterministic Finite Automata) automaton engine according to the abstract syntax tree to match the regular expression. The matching efficiency of this type of regular expression matching scheme will be seriously reduced in complex regular grammar scenarios such as complex repetitive grammar. In addition, the above scheme is mainly implemented based on a single automaton engine, and lacks effective targeted optimization for different forms of grammar rules. Based on this, the industry is still in urgent need of a new user regular expression matching scheme to achieve fast regular expression matching of input corpus in complex grammar rule scenarios. Summary of the invention

[0003] The embodiments of the present application provide a regular expression matching method, apparatus, device, storage medium and program product, which can achieve regular expression matching more quickly and accurately.

[0004] In a first aspect, an embodiment of the present application provides a regular expression matching method, the regular expression matching method comprising:

[0005] Based on a preset string set, N target strings are extracted from the to-be-matched corpus, where N is a positive integer; the preset string set includes the N target strings, and the preset string set is determined in advance based on an original non-deterministic finite automaton NFA state transition table; the original NFA state transition table is constructed in advance based on a regular expression set;

[0006] Based on the local state transition table corresponding to each target string in the N target strings, a target state transition table corresponding to the expected matching is generated;

[0007] Based on the target state transition table, regular expression matching is performed on the corpus to be matched to obtain the expected regular expression matching result to be matched;

[0008] The local state transition table is a deterministic finite automaton DFA state transition table or an NFA state transition table; the local state transition table is compressed based on the original NFA state transition table.

[0009] In some possible implementations, before generating a target state transition table corresponding to the expected match based on the local state transition table corresponding to each of the N target strings, the regular expression matching method further includes:

[0010] Based on the original NFA state transition table, determining a first valid running path of a first target string; the first target string is any target string among the N target strings;

[0011] The first valid execution path is determined as a local state transfer table corresponding to the first target character string.

[0012] In some possible implementations, determining a first valid execution path of a first target string based on an original NFA state transition table includes:

[0013] Marking the state corresponding to the first target character string in the target original state transition table as a pre-activated state; the target original state transition table is an original NFA state transition table, or a DFA state transition table obtained based on the original NFA state transition table;

[0014] The path leading to the start state of the pre-activation state and the path reachable from the end state of the pre-activation state in the target original state transition table are marked as the first valid operation path.

[0015] In some possible implementations, based on a preset string set, N target strings are extracted from the to-be-matched corpus, including:

[0016] Based on a preset string set, N target strings are extracted from the to-be-matched corpus using the single instruction multiple data (SIMD) instruction set of the central processing unit.

[0017] In some possible implementations, the target character string is a continuous character string, and the number of characters contained in the character string does not exceed a preset threshold.

[0018] In some possible implementations, before extracting N target strings from the to-be-matched corpus based on a preset string set, the regular expression matching method further includes:

[0019] Based on the regular expression set, build an abstract syntax tree;

[0020] Based on the abstract syntax tree, construct the original NFA state transition table.

[0021] In some possible implementations, the original NFA state transition table includes M repeated child nodes, where M is a non-negative integer; any repeated child node among the M repeated child nodes includes a sub-NFA state transition table; and based on the abstract syntax tree, the original NFA state transition table is constructed, including:

[0022] The repeated grammar parts in M ​​different target regular expressions are respectively constructed into sub-NFA state transition tables corresponding to the M repeated sub-nodes one by one; the target regular expression is a regular expression including the repeated grammar in the regular expression set.

[0023] In some possible implementations, after constructing the original NFA state transition table based on the abstract syntax tree, the regular expression matching method further includes:

[0024] By performing graph analysis on the target original state transition table, a continuous determined character string in the target original state transition table is extracted; the target original state transition table is an original NFA state transition table, or a DFA state transition table obtained based on the original NFA state transition table;

[0025] Based on the continuous determined character strings in the target original state transition table, a preset character string set is generated.

[0026] In some possible implementations, the preset string set includes a first string subset and K second string subsets corresponding one-to-one to the K target repeated sub-nodes; the M repeated sub-nodes include K target repeated sub-nodes, and the sub-NFA state transition table contained in the target repeated sub-nodes is used to match continuous determined strings.

[0027] Based on the same inventive concept, in a second aspect, an embodiment of the present application provides a regular expression matching device, the regular expression matching device comprising:

[0028] A first extraction module is used to extract N target strings from the to-be-matched corpus based on a preset string set, where N is a positive integer; the preset string set includes the N target strings, and the preset string set is determined in advance based on an original non-deterministic finite automaton NFA state transition table; the original NFA state transition table is constructed in advance based on a regular expression set;

[0029] A first generating module, for generating a target state transition table corresponding to the expected matching based on the local state transition table corresponding to each target string in the N target strings;

[0030] The first obtaining module is used to perform regular expression matching on the to-be-matched corpus based on the target state transition table to obtain the expected regular expression matching result to be matched;

[0031] The local state transition table is a deterministic finite automaton DFA state transition table or an NFA state transition table; the local state transition table is compressed based on the original NFA state transition table.

[0032] In a third aspect, an embodiment of the present application provides a regular expression matching device, the regular expression matching device comprising:

[0033] a processor and a memory storing computer program instructions;

[0034] When the processor executes the computer program instructions, it implements the regular expression matching method provided in any one of the above-mentioned embodiments of the present application.

[0035] In a fourth aspect, an embodiment of the present application provides a computer storage medium having computer program instructions stored thereon, and when the computer program instructions are executed by a processor, a regular expression matching method as provided in any one of the above-mentioned embodiments of the present application is implemented.

[0036] In a fifth aspect, an embodiment of the present application provides a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes a regular expression matching method provided in any one of the above-mentioned embodiments of the present application.

[0037] The embodiments of the present application provide a regular expression matching method, apparatus, device, storage medium and program product, which extracts N target strings from a corpus to be matched by using a preset string set, and the preset string set is determined in advance based on the original NFA state transition table. Then, based on the local state transition table corresponding to each target string in the N target strings, a target state transition table corresponding to the expected to be matched is generated, and the local state transition table is compressed based on the original NFA state transition table. In this way, regular expression matching is performed on the corpus to be matched based on the generated target state transition table, and the regular expression matching result expected to be matched can be quickly matched.

[0038] From the above description, it can be seen that a regular expression matching method, apparatus, device, storage medium and program product of an embodiment of the present application extracts the string features of the corpus to be matched to determine the compressed local state transition table corresponding to the string in the corpus to be matched, and merges the local state transition tables to generate a target state transition table corresponding to the corpus to be matched, which is equivalent to dynamically compressing and simplifying the original NFA state transition table and then running the automaton to match regular rules. It can effectively reduce the runtime overhead of the automaton jumping to invalid states in a large number of rule scenarios, greatly improve the runtime performance of the automaton, and thus achieve regular expression matching more quickly and accurately. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0040] Figure 1 It is a flowchart of a regular expression matching method provided in one embodiment of the present application;

[0041] Figure 2 This is an overall architecture diagram of a regular expression matching method provided in one embodiment of the present application;

[0042] Figure 3 is a schematic diagram of an abstract syntax tree provided by an embodiment of the present application;

[0043] Figure 4 is an NFA state diagram including a sub-NFA state diagram provided by an embodiment of the present application;

[0044] Figure 5 It is a schematic diagram of the pre-activation state and valid path of the NFA state diagram provided by an embodiment of the present application;

[0045] Figure 6 is an equivalent compressed NFA state diagram provided by an embodiment of the present application;

[0046] Figure 7 is a DFA state diagram provided by an embodiment of the present application;

[0047] Figure 8 is the equivalent DFA state after filtering by the prematcher provided in an embodiment of the present application Figure 1 ;

[0048] Fig. 9 is the equivalent DFA state after filtering by the prematcher provided in an embodiment of the present application Figure 2 ;

[0049] Fig.10 It is a structural diagram of a regular expression matching device provided in one embodiment of the present application;

[0050] Fig.11 It is a structural diagram of a regular expression matching device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0051] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.

[0052] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0053] As mentioned in the background technology section, the current regular expression matching solution has a serious drop in matching efficiency in complex regular grammar scenarios such as complex repetitive grammar. In addition, the above solution is mainly implemented based on a single automaton engine, lacks effective targeted optimization for different forms of grammar rules (such as string concatenation grammar, repetitive grammar, etc.), and lacks sufficient support for scenarios that require efficient, multi-rule parallel matching.

[0054] In view of the above, in order to solve the above-mentioned prior art problems, the embodiments of the present application provide a regular expression matching method, apparatus, device, computer storage medium and program product. It should be noted that the embodiments provided in the present application are not intended to limit the scope of the present application.

[0055] The following first introduces the regular expression matching method provided in the embodiment of the present application.

[0056] Figure 1 The flowchart of the regular expression matching method provided by an embodiment of the present application is shown. The regular expression matching method is applied to an electronic device, which may include a server or a user terminal. Figure 1 As shown, the regular expression matching method includes the following steps:

[0057] S110, based on a preset string set, extracting N target strings from the to-be-matched corpus, where N is a positive integer; the preset string set includes the N target strings, and the preset string set is determined in advance based on an original non-deterministic finite automaton NFA state transition table; the original NFA state transition table is constructed in advance based on a regular expression set;

[0058] S120, generating a target state transition table corresponding to the expected match based on the local state transition table corresponding to each of the N target character strings;

[0059] S130, based on the target state transition table, performing regular expression matching on the to-be-matched corpus to obtain the expected regular expression matching result to be matched.

[0060] The local state transition table is a deterministic finite automaton DFA state transition table or an NFA state transition table; the local state transition table is compressed based on the original NFA state transition table.

[0061] A regular expression matching method provided by an embodiment of the present application extracts N target strings from a corpus to be matched by using a preset string set, and the preset string set is determined in advance based on the original NFA state transition table. Then, based on the local state transition table corresponding to each target string in the N target strings, a target state transition table corresponding to the expected to be matched is generated, and the local state transition table is compressed based on the original NFA state transition table. In this way, regular expression matching is performed on the corpus to be matched based on the generated target state transition table, and the regular expression matching result expected to be matched can be quickly matched.

[0062] From the above description, it can be seen that a regular expression matching method of an embodiment of the present application extracts the string features of the corpus to be matched to determine the compressed local state transition table corresponding to the string in the corpus to be matched, and merges the local state transition tables to generate a target state transition table corresponding to the corpus to be matched, which is equivalent to dynamically compressing and simplifying the original NFA state transition table and then running the automaton to match regular rules. It can effectively reduce the runtime overhead of the automaton jumping to invalid states in a large number of rule scenarios, greatly improve the runtime performance of the automaton, and thus achieve regular expression matching more quickly and accurately.

[0063] The specific implementation of the above steps 110 to 130 is described in detail below.

[0064] In S110 , in a specific implementation, the to-be-matched corpus may be parsed according to the preset character string set acquired in advance, so as to extract N target character strings that are consistent with the character strings in the preset character string set.

[0065] The preset string set includes N target strings. The preset string set can be extracted based on the original non-deterministic finite automaton NFA state transition table. The original NFA state transition table can be constructed based on the regular expression set.

[0066] In S120, during specific implementation, based on the local state transition table corresponding to each target character string in the N target character strings, a target state transition table corresponding to the expected matching is generated.

[0067] The local state transition table corresponding to each target string in the N target strings is specifically a deterministic finite automaton DFA state transition table or an NFA state transition table, which can be determined according to the actual regular expression matching requirements. The local state transition table is compressed based on the original NFA state transition table.

[0068] In S130, during specific implementation, the target state transition table is called to perform regular expression matching on the corpus to be matched, so as to obtain the expected regular expression matching result to be matched.

[0069] It should be added that, in some embodiments, each receiving node in the target state transition table is marked with a corresponding regular expression ID. By determining the terminal state node in which the to-be-matched corpus is successfully matched in the target state transition table, the regular expression ID corresponding to the terminal state node can be obtained, thereby obtaining the regular expression matching result of the to-be-matched corpus.

[0070] According to some embodiments of the present application, optionally, in order to more reasonably determine the above-mentioned local state transition table to achieve more efficient and fast regular expression matching of the corpus to be matched, before generating a target state transition table corresponding to the expected match based on the above-mentioned local state transition table corresponding to each target string in the N target strings, the regular expression matching method may further include:

[0071] Based on the original NFA state transition table, determining a first valid running path of a first target string; the first target string is any target string among the N target strings;

[0072] The first valid execution path is determined as a local state transfer table corresponding to the first target character string.

[0073] In this embodiment, after determining the valid path of the first target string of the original NFA, the first valid running path is determined as the local state transition table corresponding to the first target string. This is equivalent to deleting the non-valid state transition path in the original NFA state transition table that is irrelevant to the valid running state of the first target string, which can be regarded as compressing the state number and transition table of the original NFA state diagram. In this way, when the NFA engine is used for regular rule matching in the future, unnecessary runtime automaton state transition overhead can be effectively reduced, which helps to fully improve the efficiency of regular expression matching.

[0074] According to some embodiments of the present application, optionally, in order to more reasonably determine the first valid running path of the first target string, the determining the first valid running path of the first target string based on the original NFA state transition table may include:

[0075] Marking the state corresponding to the first target character string in the target original state transition table as a pre-activated state; the target original state transition table is an original NFA state transition table, or a DFA state transition table obtained based on the original NFA state transition table;

[0076] The path leading to the start state of the pre-activation state and the path reachable from the end state of the pre-activation state in the target original state transition table are marked as the first valid operation path.

[0077] In this embodiment, after the first target string is extracted from the original NFA or the DFA obtained based on the conversion of the original NFA, the state corresponding to the string extracted from the original NFA / DFA graph is marked as a pre-activated state, and a graph analysis is performed based on the marked pre-activated state, so that the path to the starting state of the pre-activated state in the NFA graph and the path reachable from the end state of the pre-activated state are marked as valid paths.

[0078] That is to say, the path connecting the pre-activation state, the path leading to the starting state of the pre-activation state, and the path reachable from the pre-activation state can be regarded as the first valid running path corresponding to the first target character string.

[0079] According to some embodiments of the present application, optionally, in order to effectively improve the string matching rate and thus more efficiently achieve regular expression matching, the above-mentioned extracting N target strings from the to-be-matched corpus based on the preset string set may include:

[0080] Based on a preset string set, N target strings are extracted from the to-be-matched corpus using the single instruction multiple data (SIMD) instruction set of the central processing unit.

[0081] In this embodiment, the central processing unit (CPU); single instruction multiple data (SIMD) stream. By using the SIMD instruction set of the CPU to perform parallel accelerated matching of strings, the above N target strings can be extracted from the to-be-matched corpus at an accelerated speed.

[0082] According to some embodiments of the present application, optionally, in order to facilitate fast and efficient matching of character strings, it is necessary to limit the size of the target character string. Based on this, the above target character string is a continuous character string whose number of characters does not exceed a preset threshold.

[0083] According to some embodiments of the present application, specifically, before extracting N target strings from the to-be-matched corpus based on a preset string set, the regular expression matching method may further include:

[0084] Based on the regular expression set, build an abstract syntax tree;

[0085] Based on the abstract syntax tree, construct the original NFA state transition table.

[0086] According to some embodiments of the present application, optionally, the original NFA state transition table may include M repeated child nodes, where M is a non-negative integer. Any of the M repeated child nodes includes a sub-NFA state transition table.

[0087] The above-mentioned construction of the original NFA state transition table based on the abstract syntax tree may include:

[0088] The repeated grammar parts in M ​​different target regular expressions are respectively constructed into sub-NFA state transition tables corresponding to the M repeated sub-nodes one by one; the target regular expression is a regular expression in the regular expression set that can include repeated grammar.

[0089] According to some embodiments of the present application, in order to more reasonably generate a preset string set based on the original NFA state transition table, after constructing the original NFA state transition table based on the abstract syntax tree, the regular expression matching method may further include:

[0090] By performing graph analysis on the target original state transition table, a continuous determined character string in the target original state transition table is extracted; the target original state transition table is an original NFA state transition table, or a DFA state transition table obtained based on the original NFA state transition table;

[0091] Based on the continuous determined character strings in the target original state transition table, a preset character string set is generated.

[0092] According to some embodiments of the present application, more specifically, in combination with actual regular expression matching scenarios, in order to facilitate targeted string matching in different grammatical scenarios, the above-mentioned preset string set may include a first string subset, and K second string subsets corresponding one-to-one to the K target repeated sub-nodes.

[0093] The M repeating sub-nodes may include K target repeating sub-nodes, and the sub-NFA state transition table contained in the target repeating sub-node is used to match the continuous determined character string.

[0094] In specific application scenarios, the usage scenarios and matching order of the first string subset and the second string subset can be set in a sequence to more efficiently achieve regular expression matching in different grammatical scenarios. For example, in the early stage of regular expression matching, the first string subset can be used to extract the strings in the corpus to be matched. In the subsequent matching process, when the corpus to be matched is matched to contain repeated grammar, the second string subset of the target repeated sub-node corresponding to the corresponding repeated grammar will be further used to further extract the strings in the corpus to be matched.

[0095] In order to facilitate understanding of the regular expression matching method provided in the above embodiment, the above method is described below with reference to a specific embodiment. Figure 2 An overall architecture diagram of a regular expression matching method provided in one embodiment of the present application.

[0096] The overall system architecture consists of two parts: the compilation engine and the execution engine. The compilation engine is responsible for parsing the regular expression set, building the NFA and DFA graphs, and initializing the pre-matcher and scheduler. The execution engine schedules the operation of the NFA / DFA engine to match the regular expression of the input corpus based on the constructed NFA / DFA graph, pre-matcher, pre-activation state, and valid path analysis results. Among them, the compilation engine is mainly composed of three modules: 1. Regular expression parsing and abstract syntax tree (AST) construction module; 2. NFA graph construction, NFA pre-activation state and valid path analysis, pre-matcher construction module; 3. DFA construction, DFA pre-activation state and valid path analysis module.

[0097] Regular expression parsing and abstract syntax tree construction module: This module is responsible for parsing the regular expression set according to the regular grammar (type 3 grammar) and generating an abstract syntax tree that is isomorphic to the regular grammar and reflects the structural characteristics of the regular expression set. This abstract syntax tree will be used in the subsequent process to construct the NFA edge set and the NFA graph.

[0098] NFA graph construction, NFA pre-activation state and valid path analysis, pre-matcher construction module: This module will use the Thompson construction method to construct the original NFA graph based on the constructed abstract syntax tree. The original NFA graph mainly consists of two parts: 1. NFA state set; 2. NFA state transition table. Furthermore, this module constructs the repeated grammar part of the regular expression into a sub-NFA. For multi-layer repeated nested grammars, it optimizes and analyzes them and rewrites them into a grammar containing only one layer of repetition.

[0099] Furthermore, the module will also perform graph analysis on the constructed original NFA graph to extract the continuous deterministic strings represented in the NFA graph, and use the extracted strings to construct a pre-matcher for string matching. After extracting the continuous deterministic strings, the state corresponding to the string extracted in the NFA graph is marked as a pre-activated state, and the graph analysis is performed based on the marked pre-activated state to mark the path that can reach the start state of the pre-activated state in the NFA graph and the path that can reach from the end state of the pre-activated state as a valid path.

[0100] Pre-matcher and scheduler module in the running engine: This module matches regular expressions according to the input corpus to be matched. The module first runs the aforementioned NFA graph construction, NFA pre-activation state and valid path analysis, and the fast string matcher generated in the pre-matcher construction module to pre-match and screen the corpus to be matched through the fast string matcher, and finally extract the determined continuous string existing in the original NFA graph. Then, based on the strings extracted from the corpus to be matched and the state transition tables of each determined continuous string of the NFA / DFA pre-generated in the regular expression compilation stage, the final NFA / DFA state transition table for this regular expression matching is merged and generated, and finally the scheduler calls the NFA / DFA engine to match the regular expression.

[0101] Specifically speaking, the parsing process of the entire regular expression mentioned above can be roughly divided into two parts according to the construction direction of the abstract syntax tree AST: horizontal expansion of AST and vertical expansion of AST. The vertical expansion process of AST follows the priority order in the regular grammar, that is, the process of increasing priority. For parsing with the same priority grammar, horizontal expansion of AST is performed. When parsing a regular grammar containing brackets, recursive expansion of AST is performed.

[0102] In this embodiment, for repeated syntax in a regular expression, the repeated syntax is first parsed and optimized, and then the regular expression containing the repeated syntax is parsed. For example, the regular expression syntax ((abc|def)+){10,20} will be rewritten as (abc|def){10,} after analysis.

[0103] When the subsequent AST is constructed, the subtree root node corresponding to the regular expression containing repeated grammar will be marked as an optimized node, so that the subtree node containing repeated grammar can be further analyzed and optimized in the subsequent NFA / DFA construction process. In addition, in order to synchronously compile multiple regular expressions in the regular rule set, this embodiment uses an or operator to connect multiple regular expressions (such as: expression 1|expression 2|expression 3), and finally compiles the whole.

[0104] When constructing NFA, since the constructed NFA graph corresponds to all regular rules in the regular rule set, it is necessary to mark each NFA acceptance state to which regular expression acceptance state it belongs (i.e. mark the acceptance state ID) according to which subtree of the top layer of AST the NFA acceptance state is generated. This allows the NFA / DFA engine to match regular expressions on the corpus to be matched, and can directly determine the regular expression matching result corresponding to the corpus to be matched based on the receiving state ID corresponding to the terminal state node that successfully matched. For ease of understanding, the following is an example. Figure 3 The AST formed by merging the three regular expressions shown is used for explanation.

[0105] Figure 3 The figure shows the abstract syntax tree constructed by combining the three simplified regular grammars using or grammars. Figure 3 As shown, the three subtrees after the AST root node, subtree 1, subtree 2, and subtree 3, correspond to three different regular expressions. For example, if the accepting node of the NFA comes from the accepting node 6 of the AST, it can be seen from the AST that the accepting node 6 of the AST belongs to subtree 3, then the NFA accepting node is marked in the NFA graph as corresponding to the regular expression of subtree 3.

[0106] Based on the NFA constructed based on the Thompson construction method, this proposal further optimizes the regular expression part containing repeated grammar. In this proposal, the repeated grammar part of the regular expression is constructed as a sub-NFA. For details, see Figure 4 .

[0107] Figure 4 is an NFA state diagram including a sub-NFA state diagram provided by an embodiment of the present application. Taking the regular expression (abc|efg)+ containing repeated grammar as an example, the regular expression (abc|efg) corresponds to Figure 3The sub-NFA in the main NFA graph is mainly responsible for calling the sub-NFA to match the regular expression and counting the number of successful sub-NFA matches, and deciding whether to enter the next node based on the matching situation (whether the number of successful matches meets the lower limit of the number of repetitions corresponding to the repeated grammar). If the repeated sub-node is an accepting state in the actual matching application, the repeated sub-node will also decide whether to successfully match based on the matching situation (whether the number of successful matches meets the lower limit of the number of repetitions corresponding to the repeated grammar).

[0108] For more layers of repeated nested grammars such as ((abc|def)+){10,20}, they will be optimized and analyzed during the regular expression grammar parsing and rewritten into a grammar containing only one layer of repetition. For example, the regular expression ((abc|def)+){10,20} can be rewritten as (abc|def){10,}, and then the NFA is constructed. If the multi-layer repeated grammar cannot be merged and rewritten, the repeated child nodes will be nested in the child NFA, and so on.

[0109] At the same time, the sub-NFA of the repeated sub-node will also be analyzed by graph. When the sub-NFA of the repeated sub-node only matches continuous deterministic strings that do not exceed a certain upper limit, the sub-NFA will be converted into a string matcher (the CPU's SIMD instruction set is used in the string matcher to perform parallel accelerated string matching). Further, the constructed NFA graph is analyzed to extract the continuous deterministic strings represented in the NFA graph (which may contain multiple, such as the regular grammar abc|def can extract the strings abc and def), and the extracted strings are used to construct a pre-matcher for string matching (the matcher uses the parallel computing advantages of the CPU's SIMD instruction set to achieve fast string matching, so as to obtain a matching speed far higher than that of using a pure automaton for string matching). On this basis, the state corresponding to the string extracted from the NFA graph is marked as a pre-activated state, and a graph analysis is performed based on the marked pre-activated state to mark the path that can reach the starting state of the pre-activated state in the NFA graph and the path that can reach from the end state of the pre-activated state as valid paths (this method is applicable to both the original NFA and the sub-NFA in the original NFA).

[0110] See below Figure 5 , Figure 5 This is a schematic diagram of the pre-activated state and valid path of the NFA state diagram provided by an embodiment of the present application. The dark-background states 1, 2, 3, and 4 in the figure are pre-activated states. Starting from state 1, a unique string abc can be matched along the dark arrow, that is, the pre-activated state in the NFA diagram is the NFA state corresponding to the match of a certain finite number of strings. Figure 5The path connecting the pre-activated state, the path leading to the starting state of the pre-activated state, and the path that can be reached from the pre-activated state are valid paths. One of the important goals in the pre-activated state and valid path analysis stage of NFA is to obtain the pre-activated state and valid path that can match a certain number of continuous character strings that do not exceed a certain upper limit. After determining the pre-activated state and valid path of each continuous determined string of the original NFA, the invalid state transition path in the original NFA state transition table is deleted, and the valid state transition table of the original NFA under each continuous determined string can be obtained. Since the new state transition table corresponding to the continuous determined string eliminates the invalid state transition path, it can be regarded as compressing the number of states and the transition table of the original NFA state diagram. In the case where the NFA state corresponding to the matching continuous determined string abc is the pre-activated state, Figure 5 The NFA state diagram shown can be equivalent to Figure 6 The NFA state diagram shown.

[0111] Figure 6 is an equivalent compressed NFA state diagram provided by an embodiment of the present application. Figure 5 The original NFA state diagram shown, Figure 6 The number of states and state transition edges in the NFA state graph have been significantly compressed. Since the number of states and state transition edges in the NFA state graph have been significantly reduced, unnecessary runtime NFA state transition overhead can be effectively reduced when using the NFA engine for regular rule matching, especially when performing large-scale regular rule matching.

[0112] After the above original NFA graph is constructed, the NFA compressed runtime engine can be further constructed directly according to the constructed original NFA graph to match regular expressions using NFA.

[0113] In some feasible embodiments, considering that DFA can eliminate the uncertainty of NFA state transition. Based on this, in order to obtain higher matching efficiency, the overall architecture of the regular expression matching solution in this application (such as Figure 2 ) also includes DFA construction, DFA pre-activation state and valid path analysis modules.

[0114] The above-mentioned DFA construction, DFA pre-activation state and effective path analysis module: the NFA graph can be further converted into a DFA graph using a subset construction algorithm, and the corresponding compressed DFA running engine can be constructed to match the expected regular expression to be matched (only when the NFA graph cannot be converted into a DFA due to complex syntax or when the conversion into a DFA graph will cause the DFA state to explode, the NFA can continue to be used for regular expression matching). After the DFA graph is constructed based on the existing NFA graph using the subset construction method and the acceptance state ID of the acceptance node in the DFA is marked (that is, marking which regular expression the acceptance state of the DFA belongs to), similar to the above, the NFA pre-activation state->DFA pre-activation state remapping and DFA effective path analysis are performed (in this step, the sub-NFA in the main NFA will be converted into a sub-DFA, and the string matcher of the repeated node in the main NFA will be inherited).

[0115] After determining the pre-activated state and valid path under each determined continuous string of DFA, the ineffective state transition path in the original DFA state transition table is deleted to obtain the effective path state transition table of DFA under each determined continuous string. Similar to NFA, deleting the ineffective state transition path in the DFA state transition table is equivalent to compressing the nodes and state transition edges of the DFA state graph, which can effectively improve the operating efficiency of DFA.

[0116] Pre-matcher and scheduler modules in the running engine: Match regular expressions according to the input corpus to be matched. This module first runs NFA graph construction, NFA pre-activation state and valid path analysis, and the fast string matcher generated in the pre-matcher construction module to pre-match the corpus to be matched to filter out the determined continuous strings extracted from the original NFA graph analysis. The final NFA / DFA state transition table for this regular expression match is generated based on the strings extracted from the corpus to be matched and the state transition table of each determined continuous string of the NFA / DFA generated in the regular expression compilation phase. Finally, the scheduler calls the NFA / DFA engine to match the regular expression.

[0117] To facilitate further understanding of the complete implementation process of the regular expression matching method of the present application, the process is introduced below using a scenario implementation example. The following uses a DFA state diagram (the NFA state diagram is similar to this. Compared with the NFA state diagram, the DFA state diagram contains more features, and the use of the DFA state diagram to illustrate is more general) as an example to illustrate the overall interaction and scheduling logic of the present application.

[0118] Figure 7 is a DFA state diagram provided by an embodiment of the present application. Figure 7As shown in the figure, the starting state in the DFA state diagram may contain string matchers and sub-DFAs with multiple repeated nodes. This is caused by the repeated syntax at the beginning of multiple regular expressions. For example, three of the regular expressions in the regular expression set are (abc)+efg, (def|xyz)+efg, and [af]{10,100}xyz. After merging and compiling these three regular expressions, the DFA starting state node constructed will contain a string matcher for matching the string abc, two sub-DFA matchers for matching the regular expression def|xyz (in the actual graph optimization analysis process, the sub-NFA / DFA matching the regular expression def|xyz will be optimized to a string matcher matching the two strings def and xyz) and the regular expression [af]. The scheduler is responsible for the operation of these string matchers and sub-DFAs and the preservation of intermediate state information.

[0119] The starting state of the NFA state graph is similar to the starting state of the DFA state graph, and may also contain string matchers and sub-DFAs with multiple repeated nodes. Figure 7 The non-starting node repeated subnode 18 in the DFA includes a string matcher and two sub-DFAs. In the process of constructing DFA using the subset construction algorithm, there is a mapping process of multiple NFA state sets -> one DFA, so the non-starting node repeated subnode in the DFA state diagram may include multiple string matchers and sub-DFAs, while the repeated subnode of the non-starting node in the NFA state diagram can only include one string matcher or sub-DFA, because in the NFA state diagram, the nodes of each regular expression in the regular rule set except the starting node are decoupled from each other. This embodiment will perform relevant analysis and merging of multiple string matchers and sub-DFAs in the repeated subnodes in the NFA / DFA state diagram, such as merging between sub-NFA / DFA and string matchers, merging between string matchers, and merging between sub-NFA / DFAs.

[0120] In actual application scenarios, when matching the input corpus to be matched, the scheduler will first call the string matcher for pre-matching. Assuming that the string matcher matches the three strings abc, wxyz, and mn extracted from the original NFA in the input corpus, then state 2, state 3, state 4, state 5, state 12, state 13, state 14, state 15, state 16, state 19, state 20, and state 21 become pre-activated states. By searching and merging the valid DFA state transition tables of each string obtained in advance in the DFA compilation phase, you can merge and obtain the DFA state transition table required for this match (that is, the state corresponding to Figure 7 The dark arrow in the figure shows the DFA state transition relationship), and then the scheduler calls the automaton engine to perform the final match of this corpus.

[0121] Figure 8 is the equivalent DFA state after filtering by the prematcher provided in an embodiment of the present application Figure 1 , which is the equivalent DFA state diagram generated after the string pre-matcher matches and is used for subsequent regular expression matching.

[0122] It should be added that, in another example, if the pre-matcher matches the strings abc and wxyz extracted in the original NFA, the equivalent DFA state diagram for subsequent regular expression matching can be as follows: Fig. 9 shown.

[0123] Compare Figure 8 and Fig. 9 It can be seen that the automaton technology based on the pre-string matcher in this embodiment is essentially a dynamic automaton state compression technology. The pre-string matcher quickly scans the string of the matching corpus, and dynamically compresses the automaton state according to different scanning results, effectively avoiding the runtime overhead of jumping on the internal invalid state when using the original automaton for regular rule matching. This solution has significant efficiency advantages for the scenario of regular rule matching under a large rule set.

[0124] In summary, the embodiment of the present application realizes runtime dynamic compression of NFA / DFA states based on the pre-filtering technology, pre-activation state and valid path analysis technology of the string matcher, and effectively avoids the runtime overhead of jumping to invalid states when using NFA / DFA for regular rule matching. This embodiment has great performance advantages for large-scale regular rule matching scenarios. In addition, in this embodiment, the repeated part in the repeated grammar is reconstructed into a substring matcher or sub-NFA / DFA, which can effectively utilize the CPU's SIMD instruction set to accelerate the substring matcher and improve the runtime efficiency of NFA / DFA.

[0125] Based on the regular expression matching method provided in the above embodiment, for the same inventive concept, the present application also provides a regular expression matching device corresponding to the above regular expression matching method. Fig.10 A detailed introduction to the regular expression matching device is given.

[0126] Fig.10 A schematic diagram of the structure of a regular expression matching device provided in an embodiment of the present application is shown. Fig.10 The regular expression matching device 1000 shown includes:

[0127] The first extraction module 1010 is used to extract N target strings from the to-be-matched corpus based on a preset string set, where N is a positive integer; the preset string set includes the N target strings, and the preset string set is determined in advance based on an original non-deterministic finite automaton NFA state transition table; the original NFA state transition table is constructed in advance based on a regular expression set;

[0128] A first generating module 1020, configured to generate a target state transition table corresponding to the expected matching based on the local state transition table corresponding to each of the N target character strings;

[0129] The first obtaining module 1030 is used to perform regular expression matching on the to-be-matched corpus based on the target state transition table to obtain the expected regular expression matching result to be matched;

[0130] The local state transition table is a deterministic finite automaton DFA state transition table or an NFA state transition table; the local state transition table is compressed based on the original NFA state transition table.

[0131] A regular expression matching device provided in an embodiment of the present application, by setting corresponding functional modules, uses a preset string set to extract N target strings from a corpus to be matched, and the preset string set is determined in advance based on the original NFA state transition table. Then, based on the local state transition table corresponding to each target string in the N target strings, a target state transition table corresponding to the expected to be matched is generated, and the local state transition table is compressed based on the original NFA state transition table. In this way, regular expression matching is performed on the corpus to be matched based on the generated target state transition table, and the regular expression matching result expected to be matched can be quickly matched.

[0132] From the above description, it can be seen that a regular expression matching device of an embodiment of the present application extracts the string features of the corpus to be matched to determine the compressed local state transition table corresponding to the string in the corpus to be matched, and merges the local state transition tables to generate a target state transition table corresponding to the corpus to be matched, which is equivalent to dynamically compressing and simplifying the original NFA state transition table and then running the automaton to match regular rules. It can effectively reduce the runtime overhead of the automaton jumping to invalid states in a large number of rule scenarios, greatly improve the runtime performance of the automaton, and thus achieve regular expression matching more quickly and accurately.

[0133] According to some embodiments of the present application, optionally, before generating a target state transition table corresponding to the expected match based on the local state transition table corresponding to each of the N target strings, the regular expression matching device may further include:

[0134] The first determination module may be used to determine a first valid running path of a first target string based on an original NFA state transition table; the first target string is any target string among the N target strings;

[0135] The second determination module may be configured to determine the first valid execution path as a local state transfer table corresponding to the first target character string.

[0136] According to some embodiments of the present application, optionally, the first determining module determines the first valid running path of the first target string based on the original NFA state transition table, which may include:

[0137] The first marking submodule may be used to mark the state corresponding to the first target string in the target original state transition table as a pre-activated state; the target original state transition table is an original NFA state transition table, or a DFA state transition table obtained based on the original NFA state transition table;

[0138] The second marking submodule may be used to mark the path leading to the start state of the pre-activation state and the path reachable from the end state of the pre-activation state in the target original state transfer table as the first valid operation path.

[0139] According to some embodiments of the present application, optionally, the first extraction module 1010 extracts N target strings from the to-be-matched corpus based on a preset string set, which may include:

[0140] Based on a preset string set, N target strings are extracted from the to-be-matched corpus using the single instruction multiple data (SIMD) instruction set of the central processing unit.

[0141] According to some embodiments of the present application, optionally, the target character string is a continuous character string, and the number of characters contained in the character string does not exceed a preset threshold.

[0142] According to some embodiments of the present application, optionally, before extracting N target strings from the to-be-matched corpus based on the preset string set, the regular expression matching device may further include:

[0143] The first building module can be used to build an abstract syntax tree based on a set of regular expressions;

[0144] The second building module can be used to build an original NFA state transition table based on the abstract syntax tree.

[0145] According to some embodiments of the present application, optionally, the original NFA state transition table may include M repeated child nodes, where M is a non-negative integer; any repeated child node among the M repeated child nodes includes a sub-NFA state transition table; the second construction module, based on the abstract syntax tree, constructs the original NFA state transition table, which may include:

[0146] The repeated grammar parts in M ​​different target regular expressions are respectively constructed into sub-NFA state transition tables corresponding to the M repeated sub-nodes one by one; the target regular expression is a regular expression in the regular expression set that can include repeated grammar.

[0147] According to some embodiments of the present application, optionally, after constructing the original NFA state transition table based on the abstract syntax tree, the regular expression matching device may further include:

[0148] The second extraction module can be used to extract the continuous determined character string in the target original state transition table by performing graph analysis on the target original state transition table; the target original state transition table is the original NFA state transition table, or the DFA state transition table obtained based on the original NFA state transition table;

[0149] The second generating module may be used to generate a preset character string set based on the continuous determined character strings in the target original state transition table.

[0150] According to some embodiments of the present application, optionally, the preset string set may include a first string subset, and K second string subsets corresponding one-to-one to the K target repeated sub-nodes; the M repeated sub-nodes may include K target repeated sub-nodes, and the sub-NFA state transition table contained in the target repeated sub-node is used to match continuous determined strings.

[0151] Based on the regular expression matching method provided in the above embodiment, for the same inventive concept, the present application also provides a regular expression matching device corresponding to the above regular expression matching method. Fig.11 Provides a detailed introduction to regular expression matching devices.

[0152] See below Fig.11 , Fig.11 It is a structural diagram of a regular expression matching device provided in one embodiment of the present application.

[0153] The regular expression matching device may include a processor 1101 and a memory 1102 storing computer program instructions.

[0154] Specifically, the processor 1101 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.

[0155] The memory 1102 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 1102 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 1102 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 1102 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 1102 is a non-volatile solid-state memory.

[0156] The memory may include read-only memory (ROM), random access memory (RAM), magnetic disk storage media devices, optical storage media devices, flash memory devices, electrical, optical or other physical / tangible memory storage devices. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to an aspect of the present disclosure.

[0157] The processor 1101 implements any one of the regular expression matching methods in the above embodiments by reading and executing computer program instructions stored in the memory 1102 .

[0158] In one example, the data regular expression matching device may further include a communication interface 1103 and a bus 1110. Fig.11 As shown, the processor 1101, the memory 1102, and the communication interface 1103 are connected via a bus 1110 and communicate with each other.

[0159] The communication interface 1103 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.

[0160] Bus 1110 includes hardware, software or both, and the parts of regular expression matching device are coupled to each other.For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front side bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 1110 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.

[0161] The regular expression matching device executes the regular expression matching method in the embodiment of the present application, thereby realizing the regular expression matching method described in the embodiment of the present application.

[0162] In addition, in combination with the regular expression matching method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any regular expression matching method in the above embodiment is implemented.

[0163] Based on the regular expression matching method in the above-mentioned embodiment, an embodiment of the present application provides a computer program product. When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the regular expression matching method provided in any one of the above-mentioned embodiments of the present application.

[0164] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.

[0165] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.

[0166] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.

[0167] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.

[0168] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.

Claims

1. A regular expression matching method, It is characterized in that The method comprises: Based on a preset string set, N target strings are extracted from the to-be-matched corpus, where N is a positive integer; the preset string set includes the N target strings, and the preset string set is determined in advance based on an original non-deterministic finite automaton NFA state transition table; the original NFA state transition table is constructed in advance based on a regular expression set; Based on the local state transition table corresponding to each target string in the N target strings, generating a target state transition table corresponding to the expected matching; Based on the target state transition table, regular expression matching is performed on the to-be-matched corpus to obtain the expected regular expression matching result to be matched; The local state transition table is a deterministic finite automaton DFA state transition table or an NFA state transition table; the local state transition table is compressed based on the original NFA state transition table.

2. The method according to claim 1, It is characterized in that Before generating a target state transition table corresponding to the expected matching based on the local state transition table corresponding to each of the N target strings, the method further includes: Based on the original NFA state transition table, determining a first valid running path of a first target string; the first target string is any target string among the N target strings; The first valid execution path is determined as a local state transfer table corresponding to the first target character string.

3. The method according to claim 2, It is characterized in that The determining, based on the original NFA state transition table, a first valid execution path of the first target string comprises: Marking the state corresponding to the first target string in the target original state transition table as a pre-activated state; the target original state transition table is the original NFA state transition table, or a DFA state transition table obtained based on the original NFA state transition table; The path leading to the start state of the pre-activation state and the path reachable from the end state of the pre-activation state in the target original state transition table are marked as the first valid operation path.

4. The method according to claim 1, It is characterized in that The step of extracting N target strings from the to-be-matched corpus based on a preset string set includes: Based on the preset character string set, the N target character strings are extracted from the to-be-matched corpus using a single instruction multiple data (SIMD) instruction set of a central processing unit.

5. The method according to claim 1, It is characterized in that The target character string is a continuous character string whose number of characters does not exceed a preset threshold.

6. The method according to claim 1, It is characterized in that Before extracting N target strings from the to-be-matched corpus based on the preset string set, the method further includes: Based on the regular expression set, construct an abstract syntax tree; Based on the abstract syntax tree, the original NFA state transition table is constructed.

7. The method according to claim 6, It is characterized in that The original NFA state transition table includes M repeated child nodes, where M is a non-negative integer; any repeated child node among the M repeated child nodes includes a sub-NFA state transition table; The constructing the original NFA state transition table based on the abstract syntax tree includes: Respectively constructing repeated grammar parts in M ​​different target regular expressions into sub-NFA state transition tables corresponding to the M repeated sub-nodes one by one; The target regular expression is a regular expression in the regular expression set that includes repeated syntax.

8. The method according to claim 7, It is characterized in that After constructing the original NFA state transition table based on the abstract syntax tree, the method further includes: By performing graph analysis on the target original state transition table, a continuous determined character string in the target original state transition table is extracted; the target original state transition table is the original NFA state transition table, or a DFA state transition table obtained based on the transfer of the original NFA state transition table; The preset character string set is generated based on the continuous determined character strings in the target original state transition table.

9. The method according to claim 8, It is characterized in that The preset string set includes a first string subset and K second string subsets corresponding one-to-one to the K target repeated sub-nodes; the M repeated sub-nodes include the K target repeated sub-nodes, and the sub-NFA state transition table contained in the target repeated sub-node is used to match the continuous determined string.

10. A regular expression matching device, It is characterized in that The device comprises: A first extraction module is used to extract N target strings from the to-be-matched corpus based on a preset string set, where N is a positive integer; the preset string set includes the N target strings, and the preset string set is determined in advance based on an original non-deterministic finite automaton NFA state transition table; the original NFA state transition table is constructed in advance based on a regular expression set; A first generating module, configured to generate a target state transition table corresponding to the expected matching based on the local state transition table corresponding to each target string in the N target strings; A first obtaining module is used to perform regular expression matching on the to-be-matched corpus based on the target state transition table to obtain the expected regular expression matching result to be matched; The local state transition table is a deterministic finite automaton DFA state transition table or an NFA state transition table; the local state transition table is compressed based on the original NFA state transition table.

11. A regular expression matching device, It is characterized in that The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the regular expression matching method according to any one of claims 1 to 9 is implemented.

12. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the regular expression matching method according to any one of claims 1 to 9 is implemented.

13. A computer program product, It is characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the regular expression matching method as described in any one of claims 1 to 9.

Citation Information

Cited By

  • Information searching method and device for electronic automation design file library, equipment and medium

    CN119046233A

  • Regular matching optimization method and system based on flow collection and analysis

    CN122372235A