A method, device and storage medium for automatically generating regular expressions

By introducing data classification grading concepts and simulated annealing algorithms in API data transmission, regular expressions are automatically generated and optimized, and the problem of lack of data grading and automatic generation of regular expressions in API data transmission is solved, improving writing efficiency and data security .

CN118861829BActive Publication Date: 2025-02-07HANGZHOU MORESEC TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411338638.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-25
Publication Date
2025-02-07
Estimated Expiration
2044-09-25

AI Technical Summary

Technical Problem

The prior art lacks data grading and automatic generation of regular expressions during API data transmission, resulting in low writing efficiency and insufficient security.

Method used

By obtaining the sample response data of the API, hierarchical processing is performed according to the preset grading rules, the initial regular expression set is randomly generated, and the target regular expression set is optimized by using the simulated annealing algorithm to finally determine the final hierarchical level of the latest response data.

Benefits of technology

It realizes intelligent classification of API response data and automatic generation and optimization of regular expressions, improves the efficiency and accuracy of regular expression writing, reduces the cost and risk of manual intervention, and provides more refined and flexible data security. Protect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118861829B_ABST
    Figure CN118861829B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and storage medium for automatically generating regular expressions, which belongs to the technical field of data security and API application security, and includes the following steps: obtaining sample response data of an application program interface, and performing classification processing on the sample response data according to preset classification rules to obtain a sample classification result set; randomly generating an initial regular expression set corresponding to the classification rule based on the sample classification result set, and optimizing the initial regular expression set using a simulated annealing algorithm to obtain a target regular expression set; obtaining the latest response data of the application program interface, and determining the final classification level of the latest response data according to the target regular expression set. This application realizes intelligent classification of API response data and automatic generation and optimization of regular expressions by introducing the concept of data classification and grading and the simulated annealing algorithm, providing more sophisticated and flexible technical support for API data security protection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data security and API application security, and in particular to a method, device and storage medium for automatically generating regular expressions. Background Art

[0002] With the development of information technology and the acceleration of digital transformation, application programming interfaces (APIs) have become the core channel for modern data exchange. However, in this process, the security protection measures for API data have not kept pace with the pace of development. Most of the current technical solutions focus on data security at the database level. In terms of data processing and protection at the API level, especially the security of data during transmission, they are still insufficient.

[0003] In the existing technology, in order to ensure the security of data transmitted through API, it is usually necessary to manually write complex regular expressions to filter and verify the data. This method is not only inefficient, but also prone to human errors. Especially in the face of an increasingly complex and changing data environment, its limitations are more obvious.

[0004] That is, traditional manual methods can no longer meet the needs of efficiently and accurately classifying and grading data, and cannot flexibly adapt to diverse data security requirements. Therefore, developing a system or method that can automatically perform intelligent classification and grading based on the sensitivity and importance of the data, and can automatically generate regular expressions required for precise matching, has become an important research direction and technical challenge for improving API data security. Summary of the invention

[0005] The purpose of the present invention is to provide a method, device and storage medium for automatically generating regular expressions to solve the problems of low efficiency and low security caused by the failure to classify API data and automatically generate matching regular expressions for API data during transmission in the prior art.

[0006] To achieve the above objectives, this application adopts the following technical solutions:

[0007] The present invention provides a method for automatically generating a regular expression, comprising the following steps:

[0008] Acquire sample response data of the application program interface, and perform classification processing on the sample response data according to a preset classification rule to obtain a sample classification result set;

[0009] Based on the sample classification result set, an initial regular expression set corresponding to the classification rule is randomly generated, and the initial regular expression set is optimized by using a simulated annealing algorithm to obtain a target regular expression set;

[0010] The latest response data of the application program interface is obtained, and a final classification level of the latest response data is determined according to the target regular expression set.

[0011] Preferably, the step of obtaining sample response data of the application program interface includes:

[0012] A sample response message of the application program interface is obtained, and the sample response message is parsed according to its data format to obtain sample response data.

[0013] Preferably, the classification rules include sensitive data identification rules and importance classification standards.

[0014] Preferably, the step of performing grading processing on the sample response data according to a preset grading rule to obtain a sample grading result set includes:

[0015] Identify all sensitive data in the sample response data using the sensitive data identification rule;

[0016] Matching each sensitive data with the importance grading standard to obtain the importance level of each sensitive data;

[0017] A sample classification result set is generated according to the importance level.

[0018] Preferably, the initial regular expression set includes an initial regular expression corresponding to each classification level in the classification rule, and each of the initial regular expressions includes key features of sensitive data.

[0019] Preferably, the optimizing the initial regular expression set by using a simulated annealing algorithm to obtain a target regular expression set comprises:

[0020] Set the initial temperature, termination temperature, cooling rate and maximum number of iterations of the simulated annealing algorithm;

[0021] Selecting the best set of initial regular expressions in the initial regular expression set as the current best regular expression set, and calculating the fitness of the current best regular expression set;

[0022] Calculating a current temperature according to the cooling rate and the initial temperature, and comparing the current temperature with the termination temperature and the current number of iterations with the maximum number of iterations;

[0023] When the current temperature is higher than the termination temperature and the current number of iterations is less than the maximum number of iterations, a new optimal regular expression set and its fitness are calculated according to a perturbation strategy;

[0024] Calculating a fitness increment according to the fitness of the current optimal regular expression set and the fitness of the new optimal regular expression set;

[0025] When the fitness increment is greater than zero, the new optimal regular expression set is accepted; otherwise, the probability of accepting the new optimal regular expression set is determined according to the initial temperature and the fitness increment;

[0026] Repeat the above steps until the temperature drops to the termination temperature or the maximum number of iterations is reached, and return the latest optimal regular expression set as the target regular expression set.

[0027] Preferably, determining the final classification level of the latest response data according to the target regular expression set comprises:

[0028] Randomly select a target regular expression from the target regular expression set, and match it with the latest response data;

[0029] When the match is successful, the corresponding classification level is used as the initial classification level of the latest response data;

[0030] When the match fails, the next target regular expression is selected to match the latest response data until the initial classification level of the latest response data is determined.

[0031] Preferably, the method further comprises:

[0032] After determining the initial classification level of the latest response data, matching other target regular expressions in the target regular expression set with the latest response data in sequence;

[0033] If the new target regular expression matches successfully and its corresponding classification level is higher than the initial classification level of the latest response data, the initial classification level of the latest response data is updated to the classification level corresponding to the new target regular expression, and the remaining target regular expressions in the target regular expression set are continued to be used for matching until the target regular expression set is traversed, and the last updated classification level is used as the final classification level of the latest response data.

[0034] A device for automatically generating regular expressions, comprising:

[0035] A grading module, used to obtain sample response data of the application program interface, and to perform grading processing on the sample response data according to a preset grading rule to obtain a sample grading result set;

[0036] An optimization module, used for randomly generating an initial regular expression set corresponding to the grading rule based on the sample grading result set, and optimizing the initial regular expression set by using a simulated annealing algorithm to obtain a target regular expression set;

[0037] The matching module is used to obtain the latest response data of the application program interface and determine the final classification level of the latest response data according to the target regular expression set.

[0038] A computer-readable storage medium storing a computer program, wherein the computer program enables a computer to implement a method for automatically generating a regular expression as described in any one of the above when executed.

[0039] This application has the following beneficial effects:

[0040] By introducing the concept of data classification and grading and the simulated annealing algorithm, the intelligent classification of API response data and the automatic generation and optimization of regular expressions are realized. This not only significantly improves the efficiency and accuracy of regular expression writing and reduces the cost and risk of manual intervention, but also can dynamically adjust the matching strategy according to the sensitivity and importance of the data, providing more sophisticated and flexible technical support for API data security protection. In addition, through real-time parsing and matching of API responses, this application can also promptly discover and respond to potential security threats and enhance the overall security of API applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 It is a flowchart of a method for automatically generating a regular expression provided in an embodiment of the present application;

[0042] Figure 2 is a flow chart of determining the final classification level of the latest response data according to an embodiment of the present application;

[0043] Figure 3 It is a structural schematic diagram of a regular expression automatic generation device provided in an embodiment of the present application;

[0044] Figure 4 It is a schematic diagram of an electronic device for implementing a method for automatically generating a regular expression provided in an embodiment of the present application. DETAILED DESCRIPTION

[0045] To make the technical solution of the present application clearer, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. The terms "first", "second", etc. in the claims and specification of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances. This is only to describe the distinction method used when describing objects with the same attributes in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that a process, method, system, product or device containing a series of units is not necessarily limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or devices.

[0046] like Figure 1 As shown, this embodiment provides a method for automatically generating a regular expression, comprising the following steps:

[0047] S110, obtaining sample response data of the application program interface, and performing classification processing on the sample response data according to a preset classification rule to obtain a sample classification result set;

[0048] S120, randomly generating an initial regular expression set corresponding to the grading rules based on the sample grading result set, and optimizing the initial regular expression set using a simulated annealing algorithm to obtain a target regular expression set;

[0049] S130 , obtaining the latest response data of the application program interface, and determining the final classification level of the latest response data according to the target regular expression set.

[0050] In this embodiment, historical response data of the API is first obtained as a sample, referred to as sample response data, and then graded according to a preset grading rule. The grading rule here specifically includes a sensitive data identification rule and an importance grading standard. Specifically, all sensitive data in the sample response data are first identified using the sensitive data rule, and then the importance level of each sensitive data is determined according to the importance grading standard. Then, all the obtained importance levels are put into a set to obtain a sample grading result set. For example, the importance grading standard divides sensitive data into three levels, namely C1 (high sensitivity, such as bank card number), C2 (medium sensitivity, such as telephone number) and C3 (low sensitivity, such as address information). The sensitive data identification rule is used to identify that the sample response data contains a bank card number, a telephone number and an address information at the same time, and the bank card number belongs to the C1 level in the importance grading, the telephone number belongs to the C2 level, and the address information belongs to the C3 level. Therefore, the sample grading result set finally generated is composed of C1, C2 and C3.

[0051] Next, based on the obtained sample classification result set, a number of initial regular expressions are randomly generated as candidate solution sets for the simulated annealing algorithm. These initial regular expressions constitute the initial regular expression set. At the same time, these initial regular expressions can match a certain sensitive data in the classification rules and contain the key features of the sensitive data. For example, for personal ID number, the initial regular expression may include a structure similar to ^\d{18}$, which is used to match the pattern of 18 digits. The simulated annealing algorithm is then used to optimize the candidate solution set to obtain the target regular expression set.

[0052] Finally, the latest response data of the API is obtained, and each target regular expression in the target regular expression set is matched with the latest response data one by one to obtain the final classification level of the latest response data. Then, based on the final classification level, it is determined whether to trigger the corresponding security response mechanism.

[0053] This embodiment realizes intelligent processing and security protection of API response data by introducing data classification and grading concepts and simulated annealing algorithm and other technologies, and also provides enterprises with more efficient, accurate, flexible and compliant data processing solutions.

[0054] As data protection regulations become increasingly stringent, compliance management of API data becomes particularly important. This embodiment can help enterprises better understand and comply with relevant regulatory requirements, and ensure the compliance and standardization of API data processing through automated classification and grading and regular expression matching verification.

[0055] In some embodiments, Figure 2 As shown, the final classification level of the latest response data is determined according to the target regular expression set, including:

[0056] Randomly select a target regular expression from the target regular expression set and match it with the latest response data;

[0057] When the match is successful, the corresponding classification level is used as the initial classification level of the latest response data;

[0058] When the match fails, the next target regular expression is selected to match the latest response data until the initial classification level of the latest response data is determined.

[0059] A target regular expression is randomly selected from the target regular expression set, and it is judged whether it matches the latest response data. In fact, it is to determine whether the latest response data contains data that meets the key characteristics of the sensitive data contained in the target regular expression. If so, its corresponding classification level is used as the initial classification level of the latest response data. It should be noted here that the classification level of the sensitive data contained in the latest response data is the classification level of the entire latest response data. If not, another target regular expression in the target regular expression set is selected to match the latest response data until the initial classification level of the latest response data is obtained.

[0060] Further, after determining the initial classification level of the latest response data, other target regular expressions in the target regular expression set are matched with the latest response data in sequence;

[0061] If the new target regular expression matches successfully and its corresponding classification level is higher than the initial classification level of the latest response data, the initial classification level of the latest response data is updated to the classification level corresponding to the new target regular expression, and the remaining target regular expressions in the target regular expression set are continued to be used for matching until the target regular expression set is traversed, and the last updated classification level is used as the final classification level of the latest response data.

[0062] After determining the initial classification level of the latest response data, continue to match other target regular expressions in the target regular expression set with the latest response data one by one. If the new target regular expression matches successfully and its corresponding classification level is higher than the initial classification level, the initial classification level of the latest response data is updated, that is, its initial classification level is replaced with this classification level. Because the latest response data can have multiple sensitive data of different importance levels at the same time, for example, it contains bank card number and address information at the same time, then when matching the target regular expression, more than one regular expression can successfully match it. At this time, the highest importance level is used as the classification level of the latest response data, that is, C3 to which the bank card number belongs is used as the classification level of the latest response data. Otherwise, it is not updated, and then the remaining target regular expressions in the target regular expression set are used to continue matching with the latest response data until each target regular expression in the target regular expression set is matched with the latest response data, and then the last updated classification level is used as the final classification level of the latest response data.

[0063] This embodiment can accurately identify and protect sensitive data by performing intelligent classification and grading and regular expression matching verification on API response data, which helps to timely discover and respond to potential security threats and enhance the overall security protection capabilities of API applications.

[0064] This embodiment also supports dynamic adjustment of matching strategies according to the sensitivity and importance of the data, which means that it can flexibly deal with data of different types and levels and provide more sophisticated and personalized data processing solutions.

[0065] In some embodiments, the initial regular expression set is optimized using a simulated annealing algorithm to obtain a target regular expression set, including:

[0066] Set the initial temperature, termination temperature, cooling rate and maximum number of iterations of the simulated annealing algorithm;

[0067] Select the best set of initial regular expressions in the initial regular expression set as the current optimal regular expression set, and calculate the fitness of the current optimal regular expression set;

[0068] Calculate the current temperature according to the cooling rate and the initial temperature, and compare the current temperature with the termination temperature and the current iteration number with the maximum iteration number;

[0069] When the current temperature is higher than the termination temperature and the current number of iterations is less than the maximum number of iterations, a new optimal regular expression set and its fitness are calculated according to a perturbation strategy;

[0070] Calculating a fitness increment according to the fitness of the current optimal regular expression set and the fitness of the new optimal regular expression set;

[0071] When the fitness increment is greater than zero, the new optimal regular expression set is accepted; otherwise, the probability of accepting the new optimal regular expression set is determined according to the initial temperature and the fitness increment;

[0072] Repeat the above steps until the temperature drops to the termination temperature or the maximum number of iterations is reached, and return the latest optimal regular expression set as the target regular expression set.

[0073] Simulated annealing (SA) is a heuristic global optimization algorithm that simulates the thermal balance problem in the annealing process of solid materials to find the global optimal solution or the approximate global optimal solution. In this embodiment, the simulated annealing algorithm is used to optimize the regular expression to achieve accurate identification and protection of sensitive data. Specifically, the initial temperature T=initial_temperature, the final temperature T_min=final_temperature, the cooling rate alpha=cooling_rate and the maximum number of iterations max_iterations= preset_iterations, and then select the best set of initial regular expressions in the randomly generated initial regular expression set as the current optimal regular expression set, because in the sample response data, the same sensitive data can appear in multiple places, and its corresponding initial regular expression may also have multiple. At this time, the selection basis is the highest matching accuracy of each initial regular expression with the sample response data, and then calculate its fitness. At the same time, calculate the current temperature based on the cooling rate and the initial temperature. If the current temperature is higher than the termination temperature and the number of iterations has not reached the maximum number of iterations, add, delete or replace characters for each regular expression in the current optimal regular expression set according to the perturbation strategy to generate a new optimal regular expression set and calculate its fitness. Then, calculate the difference between the fitness of the new optimal regular expression set and the fitness of the current optimal regular expression to obtain the fitness increment delta_fitness. If the fitness increment is greater than zero, unconditionally accept the new optimal regular expression set. Otherwise, with a certain probability probability=exp(delta_fitness / T) accepts a worse solution. Specifically, when the number randomly generated by the random() function is less than probability, the new optimal regular expression set is accepted, otherwise the new optimal regular expression set is rejected. Exp represents an exponential function with e as the base. The above steps are repeated until the temperature drops to the termination temperature or the maximum number of iterations is reached, and the latest optimal regular expression set is returned as the target regular expression set. In this embodiment, it is assumed that the initial regular expression set includes ^\d{16}$ or ^\d{4}-\d{4}-\d{4}-\d{4}$, ^\d{3}-\d{3}-\d{4}$ and .*\bStreet\b.*, where ^\d{16}$ or ^\d{4}-\d{4}-\d{4}-\d{4}$ specifically corresponds to the sensitive data bank card number included in the C1 level, ^\d{3}-\d{3}-\d{4}$ corresponds to the sensitive data phone number included in the C2 level, and .*\bStreet\b.*Specifically corresponds to the sensitive data address information contained in the C3 level. First, the fitness of each initial regular expression is calculated by matching the actual data samples. Assuming that for the bank card number, an initial regular expression ^\d{16}$ can correctly match 80% of the sample data, and the matching rate of other initial regular expressions corresponding to it is 60%, then ^\d{16}$ has the highest fitness, and it is selected as the current optimal regular expression for iteration, such as modifying ^\d{16}$ to ^\d{13,16}$ to match 13 to 16 digits, or modifying ^\d{16}$ to ^\d{4}\s\d{4}\s\d{4}\s\d{4}$ to match the space separation form in the bank card number, and then iterate multiple times to finally output ^\d{13,16}$, which can match the 13 to 16-digit bank card number pattern, and the fitness reaches 90%. .

[0074] In this embodiment, the simulated annealing algorithm combines the results of data classification and grading, and regards different data categories as constraints or guiding rules in the optimization process, so that the algorithm can be more in line with the actual application scenario when generating regular expressions, rather than simply looking for the global optimal solution. At the same time, by utilizing the global search capability of the simulated annealing algorithm, the regular expression is iteratively optimized while maintaining a certain probability of accepting suboptimal solutions until an efficient and accurate matching rule is found, which can solve the problem of low efficiency and error-proneness in regular expression writing in traditional methods.

[0075] At the same time, the target regular expressions output in this embodiment can also be used in subsequent data processing, security auditing, API monitoring and other scenarios. These target regular expressions can efficiently and accurately match sensitive information in API response data, providing strong support for data security protection.

[0076] In some embodiments, Figure 3 As shown, a device for automatically generating regular expressions is provided, comprising:

[0077] The grading module 10 is used to obtain sample response data of the application program interface, and to grade the sample response data according to a preset grading rule to obtain a sample grading result set;

[0078] The optimization module 20 is used to randomly generate an initial regular expression set corresponding to the grading rules based on the sample grading result set, and optimize the initial regular expression set using a simulated annealing algorithm to obtain a target regular expression set;

[0079] The matching module 30 is used to obtain the latest response data of the application program interface and determine the final classification level of the latest response data according to the target regular expression set.

[0080] One implementation of the above-mentioned device may be: the grading module 10 obtains sample response data of the application interface, and grades the sample response data according to preset grading rules to obtain a sample grading result set; the optimization module 20 randomly generates an initial regular expression set corresponding to the grading rules based on the sample grading result set obtained by the grading module 10, and optimizes the initial regular expression set using a simulated annealing algorithm to obtain a target regular expression set; the matching module 30 obtains the latest response data of the application interface, and determines the final grading level of the latest response data according to the target regular expression set obtained by the optimization module 20.

[0081] In some embodiments, Figure 4 As shown, an electronic device is provided, including a memory 401 and a processor 402, wherein the memory 401 is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor 402 to implement the above-mentioned method for automatically generating a regular expression.

[0082] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the electronic device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0083] A computer-readable storage medium storing a computer program, wherein the computer program enables a computer to implement the above-mentioned automatic generation method of a regular expression when executed.

[0084] Exemplarily, the computer program may be divided into one or more modules / units, one or more modules / units are stored in the memory 401 and executed by the processor 402, and the I / O interface transmission of data is completed by the input interface 405 and the output interface 406 to complete the present invention. The one or more modules / units may be a series of computer program instruction segments that can complete specific functions, and the instruction segments are used to describe the execution process of the computer program in the computer device.

[0085] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may include, but is not limited to, a memory 401 and a processor 402. Those skilled in the art may understand that this embodiment is only an example of a computer device and does not constitute a limitation on the computer device. The computer device may include more or fewer components, or a combination of certain components, or different components. For example, the computer device may also include an input device 407, a network access device, a bus, etc.

[0086] The processor 402 may be a central processing unit (CPU), or other general-purpose processors 402, digital signal processors 402 (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor 402 may be a microprocessor 402 or the processor 402 may also be any conventional processor 402, etc.

[0087] The memory 401 may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. The memory 401 may also be an external storage device of the computer device, such as a plug-in hard disk equipped on the computer device, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Further, the memory 401 may include both an internal storage unit of the computer device and an external storage device. The memory 401 is used to store computer programs and other programs and data required by the computer device. The memory 401 may also be used to temporarily store in the output device 408, and the aforementioned storage media include various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory ROM403, a random access memory RAM404, a disk or an optical disk.

[0088] The above-mentioned embodiments only express several implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the patent of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A method for automatically generating regular expressions, characterized in that: The following steps are involved: Obtaining sample response data of the application program interface, and performing classification processing on the sample response data according to preset classification rules to obtain a sample classification result set, wherein the classification rules include sensitive data identification rules and importance classification standards; Based on the sample classification result set, an initial regular expression set corresponding to the classification rule is randomly generated, and the initial regular expression set is optimized by using a simulated annealing algorithm to obtain a target regular expression set; Acquire the latest response data of the application program interface, and determine the final classification level of the latest response data according to the target regular expression set; The step of optimizing the initial regular expression set by using a simulated annealing algorithm to obtain a target regular expression set includes: Set the initial temperature, termination temperature, cooling rate and maximum number of iterations of the simulated annealing algorithm; Selecting the best set of initial regular expressions in the initial regular expression set as the current best regular expression set, and calculating the fitness of the current best regular expression set; Calculating a current temperature according to the cooling rate and the initial temperature, and comparing the current temperature with the termination temperature and the current number of iterations with the maximum number of iterations; If the current temperature is higher than the termination temperature and the current number of iterations is less than the maximum number of iterations, a new optimal regular expression set and its fitness are calculated according to a perturbation strategy; Calculating a fitness increment according to the fitness of the current optimal regular expression set and the fitness of the new optimal regular expression set; If the fitness increment is greater than zero, the new optimal regular expression set is accepted; otherwise, the probability of accepting the new optimal regular expression set is determined according to the initial temperature and the fitness increment; Repeat the above steps until the temperature drops to the termination temperature or the maximum number of iterations is reached, and return the latest optimal regular expression set as the target regular expression set.

2. The method for automatically generating a regular expression according to claim 1, characterized in that: The sample response data of the application program interface is obtained, including: A sample response message of the application program interface is obtained, and the sample response message is parsed according to its data format to obtain sample response data.

3. The automatic generation method of a regular expression according to claim 1, characterized in that: The step of performing grading processing on the sample response data according to a preset grading rule to obtain a sample grading result set includes: Identify all sensitive data in the sample response data using the sensitive data identification rule; Matching each sensitive data with the importance grading standard to obtain the importance level of each sensitive data; A sample classification result set is generated according to the importance level.

4. The automatic generation method of a regular expression according to claim 3, characterized in that: The initial regular expression set includes an initial regular expression corresponding to each classification level in the classification rule, and each of the initial regular expressions includes key features of sensitive data.

5. The method for automatically generating a regular expression according to claim 1, characterized in that: Determining the final classification level of the latest response data according to the target regular expression set includes: Randomly select a target regular expression from the target regular expression set, and match it with the latest response data; If the match is successful, the corresponding classification level is used as the initial classification level of the latest response data; If the match is unsuccessful, the next target regular expression is selected to match the latest response data until the initial classification level of the latest response data is determined.

6. The method for automatically generating a regular expression according to claim 5, characterized in that: The method further comprises: After determining the initial classification level of the latest response data, matching other target regular expressions in the target regular expression set with the latest response data in sequence; If the new target regular expression matches successfully and its corresponding classification level is higher than the initial classification level of the latest response data, the initial classification level of the latest response data is updated to the classification level corresponding to the new target regular expression, and the remaining target regular expressions in the target regular expression set are continued to be used for matching until the target regular expression set is traversed, and the last updated classification level is used as the final classification level of the latest response data.

7. A regular expression automatic generation device, characterized in that: include: A grading module, used to obtain sample response data of the application program interface, and to perform grading processing on the sample response data according to preset grading rules to obtain a sample grading result set, wherein the grading rules include sensitive data identification rules and importance grading standards; An optimization module, used for randomly generating an initial regular expression set corresponding to the grading rule based on the sample grading result set, and optimizing the initial regular expression set by using a simulated annealing algorithm to obtain a target regular expression set; A matching module, used for acquiring the latest response data of the application program interface, and determining a final classification level of the latest response data according to the target regular expression set; The optimization module optimizes the initial regular expression set using a simulated annealing algorithm to obtain a target regular expression set, including: Set the initial temperature, termination temperature, cooling rate and maximum number of iterations of the simulated annealing algorithm; Selecting the best set of initial regular expressions in the initial regular expression set as the current best regular expression set, and calculating the fitness of the current best regular expression set; Calculating a current temperature according to the cooling rate and the initial temperature, and comparing the current temperature with the termination temperature and the current number of iterations with the maximum number of iterations; If the current temperature is higher than the termination temperature and the current number of iterations is less than the maximum number of iterations, a new optimal regular expression set and its fitness are calculated according to a perturbation strategy; Calculating a fitness increment according to the fitness of the current optimal regular expression set and the fitness of the new optimal regular expression set; If the fitness increment is greater than zero, the new optimal regular expression set is accepted; otherwise, the probability of accepting the new optimal regular expression set is determined according to the initial temperature and the fitness increment; Repeat the above steps until the temperature drops to the termination temperature or the maximum number of iterations is reached, and return the latest optimal regular expression set as the target regular expression set.

8. A computer-readable storage medium storing a computer program, characterized in that: The computer program enables a computer to implement an automatic generation method of a regular expression as claimed in any one of claims 1 to 6 when executed.

Citation Information

Patent Citations

  • Data extraction method, device and system and computer readable storage medium

    CN113656659A

  • Regular expression generation method and device, intelligent terminal and computer storage medium

    CN115269939A