CN112989762B - Complex character string pattern matching method based on Socket protocol - Google Patents
Complex character string pattern matching method based on Socket protocol Download PDFInfo
- Publication number
- CN112989762B CN112989762B CN202110314658.XA CN202110314658A CN112989762B CN 112989762 B CN112989762 B CN 112989762B CN 202110314658 A CN202110314658 A CN 202110314658A CN 112989762 B CN112989762 B CN 112989762B
- Authority
- CN
- China
- Prior art keywords
- string
- parameter
- self
- template
- circulation
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/12—Use of codes for handling textual entities
- G06F40/126—Character encoding
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Document Processing Apparatus (AREA)
Abstract
The invention provides a complex character string pattern matching method based on Socket protocol, which relates to the technical field of computers and comprises the following steps: defining a template string and a cache structure body of the parameter string, wherein the template string comprises parameter names, and the cache structure body stores all the parameter names and corresponding parameter values thereof; acquiring a self-circulation template string in the template string, analyzing parameters to be spliced contained in parameter names in the self-circulation template string, and recording the number of the parameters; taking out parameter values corresponding to the splicing parameters from the cache structure body; according to the number of the parameters, splicing the parameter values in sequence to obtain a self-circulation character string; and splicing the self-circulation character string with the rest part of the template string to obtain the target character string. According to the invention, the data which is originally required to be obtained through hard coding one by one is changed into the data which is circularly obtained through the template through the mode matching method, so that developers do not need to analyze each parameter type one by one, and the development efficiency is improved.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a Socket protocol-based complex character string pattern matching method.
Background
Although string matching algorithms have been developed for decades, very practical algorithms are only recently, and research on string matching problems has a dislocation between theoretical research and practical application, and a learner who is specially engaged in algorithm research is concerned with algorithms which are very attractive in theory, and developers pursue algorithms which are as fast as practical in practical application, so that algorithms (such as BNDM algorithms) combining theoretical research and practical application only have appeared in recent years and are still in a development stage.
At present, in the process of data interaction between each bank and peripheral systems, due to different bill settings of each bank system, when bill contents are transmitted, codes are written to acquire data information item by item, and the data information has the characteristics of large data quantity and strong data formatting.
When complex character strings are matched by adopting a traditional string matching method, each parameter value needs to be acquired by adopting hard coding, so that the problems of large development workload and low development efficiency of developers are caused, and different bill information is matched, and recoding is needed because the parameter names in the bills are different and the arrangement sequence is different, so that the matching method of the complex character strings needs to be provided, and the development efficiency is improved.
Disclosure of Invention
Aiming at the problems, the invention provides a Socket protocol-based complex character string pattern matching method, which completes matching and splicing of multi-nesting multi-cycle complex structure character strings by configuring templates.
In order to achieve the above object, the present invention provides a method for matching complex character string patterns based on Socket protocol, comprising:
defining a template string and a cache structure body of a parameter string, wherein the template string comprises parameter names, and all the parameter names and corresponding parameter values are stored in the cache structure body;
acquiring a self-circulation template string in the template string, analyzing parameters to be spliced contained in parameter names in the self-circulation template string, and recording the number of the parameters;
taking out parameter values corresponding to all splicing parameters from the cache structure body;
according to the number of the parameters, splicing the parameter values in sequence to obtain a self-circulation character string;
and splicing the self-circulation character string with the rest part of the template string to obtain a target character string.
As a further improvement of the present invention, a temporary structure array is defined in the cache structure of the parameter string, and the parameter values corresponding to the splicing parameters are taken out of the cache structure and put into the temporary structure array.
According to the invention, traversing the temporary structure body array according to the parameter number, and sequentially splicing the parameter values to obtain the self-circulation character string.
As a further improvement of the present invention, the number of loops of the plurality of parameters in the same self-loop character string is the same.
As a further improvement of the present invention, when the number of parameters to be spliced included in each parameter name in the self-circulation template string is different, the number of circulation times of the self-circulation template string is based on a small number.
As a further improvement of the invention, the template string comprises a separator, the separator comprises a start character and an end character, and a self-circulation template string is arranged between the start character and the end character.
As a further improvement of the invention, when the self-circulation template string in the template string is obtained, firstly judging whether the template string comprises a starting symbol or not, if the starting symbol is included, further judging whether the template string comprises an ending symbol or not,
if the end symbol is also included, the template string between the start symbol and the end symbol is acquired as a self-circulation template string.
As a further improvement of the invention, if the initiator is not included, returning, and ending the cycle; if the end symbol is not included, the loop is skipped and the next loop is entered.
As a further improvement of the present invention, a definition counter counts the number of parameters to be spliced contained in each parameter name in the self-circulation template string.
As a further development of the invention, the length of the parameter is noted after the name of the parameter in the template string.
Compared with the prior art, the invention has the beneficial effects that:
the data which is originally required to be obtained through hard coding one by one is changed into the data which is circularly obtained through the template through the mode matching method, a developer does not need to analyze each parameter type one by one, only the data is required to be configured in the template, and the development efficiency of the developer is improved.
The pattern matching method has good universality of the template string, can be suitable for character strings of a plurality of socket messages, is easy to maintain, and can be directly modified without modifying codes when the parameter types and sequences need to be modified or adjusted.
Drawings
Fig. 1 is a flowchart of a complex string pattern matching method based on Socket protocol according to an embodiment of the present invention;
fig. 2 is a block diagram of a matching and splicing process of template strings according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The invention is described in further detail below with reference to the attached drawing figures:
as shown in fig. 1, the method for matching complex character string patterns based on Socket protocol provided by the invention comprises the following steps:
s1, defining a template string and a cache structure body of the parameter string, wherein the template string comprises parameter names, and all the parameter names and corresponding parameter values are stored in the cache structure body;
wherein, the liquid crystal display device comprises a liquid crystal display device,
the length of the parameter is noted after the name of the parameter in the template string.
A temporary structure array is defined in a cache structure of the parameter string, and parameter values corresponding to each splicing parameter are taken out of the cache structure and put into the temporary structure array.
Traversing the temporary structure body array according to the number of the parameters, and sequentially splicing the parameter values to obtain the self-circulation character string.
S2, acquiring a self-circulation template string in the template string, analyzing parameters to be spliced contained in parameter names in the self-circulation template string as shown in FIG. 2, and recording the number of the parameters;
wherein, the liquid crystal display device comprises a liquid crystal display device,
the template string comprises a separator, the separator comprises a start character and an end character, and a self-circulation template string is arranged between the start character and the end character; when the self-circulation template string in the template string is acquired, firstly judging whether the template string comprises a starting symbol or not, if the starting symbol is included, further judging whether the template string comprises an ending symbol or not,
if the end symbol is also included, the template string between the start symbol and the end symbol is acquired as a self-circulation template string.
If the initiator is not included, returning, and ending the cycle; if the end symbol is not included, the loop is skipped and the next loop is entered.
In addition, the number of loops of a plurality of parameters in the same self-loop character string is the same; and counting the number of parameters to be spliced contained in each parameter name in the self-circulation template string by adopting a definition counter, wherein when the number of parameters to be spliced contained in each parameter name in the self-circulation template string is different, the circulation times of the self-circulation template string are less.
S3, taking out parameter values corresponding to the splicing parameters from the cache structure body;
s4, splicing the parameter values in sequence according to the number of the parameters to obtain a self-circulation character string;
and S5, splicing the self-circulation character string and the rest part of the template string to obtain the target character string.
Examples:
the method can be applied to the analysis and splicing scene of the fixed character string position, and various protocol adapters based on socket protocols can use the technology, and the protocol definition of the H2 protocol adapter is as follows: and (3) carrying out short connection synchronous communication by adopting a standard socket protocol, and adopting an ASCII Stream (STREM) mode facing stable connection. Taking an H2 protocol adapter as an example, the pattern matching of the complex character strings when the interactive data is acquired is as follows:
step 1, defining a buffer structure body of a template string and a parameter string;
firstly, information interaction is carried out between money information of a certain bank and a peripheral system, and the information to be circularly acquired is as follows:
field name | Field length | Format description |
Contract number | 20 | |
User name | 60 | |
1 | 0x0A record separator | |
Sequence number | 2 | |
Expense item name 1 | 20 | Character(s) |
Cost amount 1 | 10 | Character(s) |
Expense project name 2 | 20 | Character(s) |
Cost amount 2 | 10 | Character(s) |
1 | 0x0A record separator | |
1 | 0x1A packet end flag |
Other remaining configuration needed parts:
according to the above information, the information to be circularly acquired is written into the self-circulation template string, and other remaining parts to be configured are also written into the template string, and examples are as follows:
%VERSION(2)%%PKG_LENGTH(5)%%SEQUEUE(20)%%RETN_FLAG(1)%%SERVICE_FLAG(12)%%SERVICE_NUMBER(20)%NUMBER_TYPE(1)%%LOGIN_NO(6)%%LOGIN_ADDR(6)%%PKG_NUMBER(5)%%LAST_FLA G(1)%%ERRNO(5)%%BALANCE_CODE(20)%%USER_NAME(60)%%ICOU NT(2)%{///%FEE_NAME(20)%%FEE_NUMBER(10)%///}
wherein,%% is the separator, VERSION, PKG_ LENGTH, SEQUEUE and the like between the separators are parameter names, and numerals in brackets after the parameter names are the lengths of the parameters;
the parts of the {///as the start and///} as the end, and the {///and// } are enclosed represent the self-circulating template string, there are multiple loops.
Then, a cache structure of parameter strings is defined:
the acParaName stores the name of each parameter in the template string, and acParaValue stores the specific value of the parameter in the template string.
Then, a temporary structure array is defined, and the maximum parameter number of the array is defined.
# defined MAXPARA 100/. About.maximum number of parameters
STRWORKPARASTRworking Para [ MAXPARA ]; parameter string array
Step 2, acquiring a self-circulation template string in the template string, analyzing parameters to be spliced contained in parameter names in the self-circulation template string, and recording the number of the parameters;
the self-circulation template string is as follows:
{///%FEE_NAME(20)%%FEE_NUMBER(10)%///}
the form of FEE_NAME is a1|a2|a3; the form of FEE_NUMBER is b1|b2|b3;
wherein | is a separator, and data a1, a2, a3, b1, b2, b3 separated by | are recorded;
recording the number of the parameters separated by I in each parameter name, wherein the number of the parameters is 3, and the circulation times are the same;
step 3, taking out parameter values corresponding to all splicing parameters from the cache structure body, and respectively putting the parameter values into a temporary structure body array tmparr;
step 4, traversing the tmparr array according to the number of the parameters which is 3, and sequentially splicing the parameter values to obtain a self-circulation character string; the shape is as follows: a1 b 1a 2 b2 a3 b3;
and 5, splicing the self-circulation character string with the rest part of the template string to obtain the target character string.
The invention has the advantages that:
the data which is originally needed to be obtained through hard coding one by one is changed into the data which is circularly obtained through the template through a mode matching method, and a developer does not need to analyze each parameter type one by one and only needs to be configured in the template.
The template has good universality, can adapt to the string operation of a plurality of SOCKET messages, is easy to maintain, and only needs to adjust the parameter configuration template and does not need to modify codes when the parameter types needing to be matched need to be modified or adjusted.
The above is only a preferred embodiment of the present invention, and is not intended to limit the present invention, but various modifications and variations can be made to the present invention by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (9)
1. A Socket protocol-based complex character string pattern matching method is characterized by comprising the following steps:
defining a template string and a cache structure body of a parameter string, wherein the template string comprises parameter names, and all the parameter names and corresponding parameter values are stored in the cache structure body;
acquiring a self-circulation template string in the template string, analyzing parameters to be spliced contained in parameter names in the self-circulation template string, and recording the number of the parameters;
a temporary structure array is defined in the buffer structure of the parameter string, and the parameter values corresponding to the splicing parameters are taken out of the buffer structure and put into the temporary structure array
Performing cyclic traversal and splicing on the parameter values in all the temporary structure body arrays to obtain a self-cyclic character string;
and splicing the self-circulation character string with the rest part of the template string to obtain a target character string.
2. The method according to claim 1, characterized in that: traversing the temporary structure body array according to the parameter number, and splicing the parameter values in sequence to obtain a self-circulation character string.
3. The method according to claim 1, characterized in that: the number of loops of the plurality of parameters in the same self-loop character string is the same.
4. A method according to claim 1 or 3, characterized in that: when the number of parameters to be spliced contained in each parameter name in the self-circulation template string is different, the circulation times of the self-circulation template string are less.
5. The method according to claim 1, characterized in that: the template string comprises a separator, the separator comprises a start character and an end character, and a self-circulation template string is arranged between the start character and the end character.
6. The method according to claim 5, wherein: when the self-circulation template string in the template string is acquired, firstly judging whether the template string comprises a starting symbol or not, if so, further judging whether the template string comprises an ending symbol or not,
if the end symbol is also included, the template string between the start symbol and the end symbol is acquired as a self-circulation template string.
7. The method according to claim 6, wherein: if the initiator is not included, returning, and ending the cycle; if the end symbol is not included, the loop is skipped and the next loop is entered.
8. The method according to claim 1, characterized in that: and the definition counter counts the number of parameters to be spliced contained in each parameter name in the self-circulation template string.
9. The method according to claim 1, characterized in that: the length of the parameter is noted after the name of the parameter in the template string.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110314658.XA CN112989762B (en) | 2021-03-24 | 2021-03-24 | Complex character string pattern matching method based on Socket protocol |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110314658.XA CN112989762B (en) | 2021-03-24 | 2021-03-24 | Complex character string pattern matching method based on Socket protocol |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112989762A CN112989762A (en) | 2021-06-18 |
CN112989762B true CN112989762B (en) | 2023-08-25 |
Family
ID=76333417
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110314658.XA Active CN112989762B (en) | 2021-03-24 | 2021-03-24 | Complex character string pattern matching method based on Socket protocol |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112989762B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN114285906B (en) * | 2021-12-24 | 2024-01-23 | 北京天融信网络安全技术有限公司 | Message processing method and device, electronic equipment and storage medium |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6039245A (en) * | 1996-06-10 | 2000-03-21 | Diebold, Incorporated | Financial transaction processing system and method |
CN105721154A (en) * | 2014-12-05 | 2016-06-29 | 航天信息股份有限公司 | Encryption protection method based on Android platform communication interface |
CN106951255A (en) * | 2017-03-23 | 2017-07-14 | 福建中金在线信息科技有限公司 | A kind of processing method and processing device of splicing character string |
CN107870765A (en) * | 2016-09-26 | 2018-04-03 | 平安科技(深圳)有限公司 | Message joining method and terminal |
CN108881125A (en) * | 2017-05-15 | 2018-11-23 | 武汉斗鱼网络科技有限公司 | Parse method, storage medium, equipment and the system of communication protocol |
CN111078573A (en) * | 2019-12-24 | 2020-04-28 | 深圳前海微众银行股份有限公司 | Test message generation method and device |
CN112328231A (en) * | 2020-10-14 | 2021-02-05 | 远江盛邦(北京)网络安全科技股份有限公司 | Quick conversion method between python dictionary and structure |
CN112330202A (en) * | 2020-11-25 | 2021-02-05 | 中盈优创资讯科技有限公司 | Control intention work order module based on arranging control flow service fulfillment |
-
2021
- 2021-03-24 CN CN202110314658.XA patent/CN112989762B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6039245A (en) * | 1996-06-10 | 2000-03-21 | Diebold, Incorporated | Financial transaction processing system and method |
CN105721154A (en) * | 2014-12-05 | 2016-06-29 | 航天信息股份有限公司 | Encryption protection method based on Android platform communication interface |
CN107870765A (en) * | 2016-09-26 | 2018-04-03 | 平安科技(深圳)有限公司 | Message joining method and terminal |
CN106951255A (en) * | 2017-03-23 | 2017-07-14 | 福建中金在线信息科技有限公司 | A kind of processing method and processing device of splicing character string |
CN108881125A (en) * | 2017-05-15 | 2018-11-23 | 武汉斗鱼网络科技有限公司 | Parse method, storage medium, equipment and the system of communication protocol |
CN111078573A (en) * | 2019-12-24 | 2020-04-28 | 深圳前海微众银行股份有限公司 | Test message generation method and device |
CN112328231A (en) * | 2020-10-14 | 2021-02-05 | 远江盛邦(北京)网络安全科技股份有限公司 | Quick conversion method between python dictionary and structure |
CN112330202A (en) * | 2020-11-25 | 2021-02-05 | 中盈优创资讯科技有限公司 | Control intention work order module based on arranging control flow service fulfillment |
Also Published As
Publication number | Publication date |
---|---|
CN112989762A (en) | 2021-06-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107239954B (en) | Method and device for increasing block generation speed | |
JP2024045394A (en) | Method and system for blockchain implementation script-based byte interpretation | |
US10847136B2 (en) | System and method for mapping a customer journey to a category | |
CN103927314B (en) | A kind of method and apparatus of batch data processing | |
CN109670081A (en) | The method and device of service request processing | |
CN103294652B (en) | A kind of data transfer device and system | |
CN105488210B (en) | A kind of batch data matching process and device | |
CN110275861A (en) | Date storage method and device, storage medium, electronic device | |
WO2022048511A1 (en) | Differential upgrade method for intelligent gas meter firmware | |
CN112989762B (en) | Complex character string pattern matching method based on Socket protocol | |
CN110472154A (en) | A kind of resource supplying method, apparatus, electronic equipment and readable storage medium storing program for executing | |
CN110781230A (en) | Data access method, device and equipment | |
CN110233741A (en) | Service charging method, device, equipment and storage medium | |
CN112784112A (en) | Message checking method and device | |
CN109684457A (en) | A kind of method and system that personal share advertisement data is extracted | |
CN116737482A (en) | Method and device for collecting chip test data in real time and electronic equipment | |
CN102541639B (en) | CPU (Central Processing Unit) card data processing method, CPU card data processing system and CPU card | |
CN109726313A (en) | The method and device of operating database | |
CN110019363A (en) | A kind of method and apparatus verifying data | |
CN109714652A (en) | Date storage method, system, storage medium and the equipment of ODN management system | |
CN110083501A (en) | Interface calls method of counting and device | |
JP2001307008A (en) | Form image processor | |
CN105207807B (en) | A kind of SIM card flow analysis method applied to power information acquisition system | |
CN101771675B (en) | Method and device for implementing feature matching of data packet | |
CN110222286A (en) | Information acquisition method, device, terminal and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |