Search

CN-121981086-A - Multi-line text searching and replacing method and system thereof

CN121981086ACN 121981086 ACN121981086 ACN 121981086ACN-121981086-A

Abstract

The invention relates to a multi-line text searching and replacing method and a system thereof, wherein the method comprises the steps of respectively preprocessing original multi-line text, multi-line searching content and multi-line replacing content, removing head and tail spaces of each line, respectively obtaining corresponding logic text, logic searching content and logic replacing content, judging whether the logic searching content contains a preset wildcard, if the logic searching content does not contain the preset wildcard, carrying out simple character string matching on the logic text, obtaining a logic index searching result, converting the logic index searching result into an original character index by utilizing a preset index mapping relation, carrying out positioning, and carrying out simple replacing operation, if the preset wildcard is contained, taking the logic searching content as an integral matching block, carrying out sliding comparison according to lines in a line array corresponding to the logic text, if the matching is successful, extracting a starting and stopping line index of a fuzzy item list and the matching block, carrying out positioning by utilizing the index mapping relation, and executing the fuzzy replacing operation of inserting the fuzzy item list into the placeholder.

Inventors

  • WAN HUAJIAN
  • LEI QIANG
  • WANG QILIN
  • DAI HAO
  • CHEN WEI
  • LI YING
  • MAI YINGJIAN

Assignees

  • 深圳供电局有限公司

Dates

Publication Date
20260505
Application Date
20260115

Claims (10)

  1. 1. A multi-line text search replacement method, comprising the steps of: acquiring an original multi-line text to be processed, and a multi-line searching content and a multi-line replacing content which are input by a user; Preprocessing the original multi-line text, the multi-line searching content and the multi-line replacing content respectively, removing head and tail spaces of each line, and obtaining corresponding logic text, logic searching content and logic replacing content respectively; judging whether the logic searching content contains a preset wildcard or not; If the logical text does not contain the preset wildcard, executing a first branch flow, performing simple character string matching on the logical text to obtain a logical index searching result, converting the logical index searching result into an original character index by using a preset index mapping relation for positioning, and executing simple replacement operation; if the fuzzy item list and the starting and stopping row index of the matching block are successfully matched, positioning is carried out by utilizing the index mapping relation, and fuzzy replacement operation of inserting the fuzzy item list into the placeholder is carried out; After the replacement operation is completed, the leading and trailing spaces of the text are restored.
  2. 2. The method of claim 1, wherein the preset index mapping relationship is established by: establishing a bidirectional mapping dictionary between an original index and a logical index from which the head and tail space of each row is removed; The keys of the first mapping dictionary are character indexes of the original text, the values are corresponding indexes in the logical text, the keys of the second mapping dictionary are corresponding indexes in the logical text, and the values are character indexes of the original text.
  3. 3. The method according to claim 1, wherein the performing simple string matching in the first branch flow specifically comprises: Obtaining a logical index searching range according to the original index searching range and the first mapping dictionary; and searching the logic searching content in the logic index searching range.
  4. 4. The method according to claim 1, wherein the performing row-wise sliding alignment in the second branching flow specifically comprises: analyzing each line of searching templates, and intelligently matching with the target line; And if all the lines of the multi-line searching content are successfully matched in sequence, recording the multi-line searching content as a replacement information object, wherein the replacement information object comprises a start-stop line index of the matching block and the fuzzy item list.
  5. 5. The method according to claim 1, wherein said performing a fuzzy substitution operation of inserting said fuzzy item list into a placeholder, comprises in particular: Resolving placeholders in the logic substitution content; And replacing the placeholder by using the extracted fuzzy item list to generate an actual replacement text.
  6. 6. The method of claim 1, wherein when performing the fuzzy substitution operation, the substitution step comprises: traversing all rows, identifying all matching blocks and generating corresponding replacement information objects; constructing a row hash table according to the replacement information object, wherein keys of the row hash table are all row indexes between start and stop row indexes of the replacement information object; Constructing a line dictionary according to the replacement information object, wherein the keys of the line dictionary are the first line index of the replacement information object, and the values are the replacement information object; Traversing an original line text, and reorganizing the text by using the line hash table and a line dictionary, wherein the original line text is directly added if a current line index is not in the line hash table, and the line text after replacement of a replacement information object corresponding to the line dictionary is added if the current line index is a key of the line dictionary; and restoring the head and tail spaces of each line of the recombined text.
  7. 7. A multi-line text search replacement system accommodating head-to-tail space effects, comprising means for performing the method of any of claims 1-6.
  8. 8. An electronic device, comprising: A communication interface for communicating with other electronic devices; A memory for storing computer program instructions; A processor for executing the computer program instructions to support the electronic device to implement the method according to any one of claims 1 to 6.
  9. 9. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any one of claims 1 to 6.
  10. 10. A computer program product comprising computer program instructions for instructing a computer device to perform the operations corresponding to the method as claimed in any one of claims 1 to 6.

Description

Multi-line text searching and replacing method and system thereof Technical Field The invention relates to the technical field of intersection of artificial intelligence and information retrieval, in particular to a multi-line text searching and replacing method and a system thereof. Background In existing text editors (e.g., microsoft Word, WPS, code editors) and various specialized text processing systems, find replacement functions are one of the most basic and important functions. However, in processing complex text, the prior art has the following technical problems: (1) The head and tail spaces influence the index positioning problem that when text searching and replacing are carried out, the head and tail spaces (including blank characters such as spaces and tab making) of the text line can directly influence the calculation of the character index. For example, a line of text is preceded by 2 spaces, and matching directly by character index may result in offset errors. The prior art either ignores spaces entirely (which may result in a mismatch) or requires a strict match (poor user experience), lacks a mechanism to intelligently handle head-to-tail spaces while maintaining accurate positioning. (2) The problem of matching across multiple lines is that conventional search alternatives are typically based on a single line of text or an entire block of text, making it difficult to achieve an exact correspondence of "multiple line search content" to "multiple line replacement content". For example, a user may need to replace three lines of the operating steps with four lines of new steps, which requires accurate identification of the matched start and stop lines and maintenance of the structural integrity of the replaced text. (3) Fuzzy matching and wild card support problems-professional field text (e.g., power ticket) often contains variable parts (e.g., device name, number, etc.). Existing wildcards (e.g., x) are simple to implement, but it is difficult to correctly pass matching "fuzzy terms" to the corresponding locations (e.g., \1, \2 placeholders) of the replacement text in multiple line substitutions. The extraction and transfer of ambiguous terms is particularly complex, especially in a multi-line context. Disclosure of Invention The invention aims to provide a multi-line text searching and replacing method and a system thereof, which solve the technical problems. To achieve the above object, according to a first aspect of the present invention, there is provided a multi-line text search replacement method, comprising the steps of: acquiring an original multi-line text to be processed, and a multi-line searching content and a multi-line replacing content which are input by a user; Preprocessing the original multi-line text, the multi-line searching content and the multi-line replacing content respectively, removing head and tail spaces of each line, and obtaining corresponding logic text, logic searching content and logic replacing content respectively; judging whether the logic searching content contains a preset wildcard or not; If the logical text does not contain the preset wildcard, executing a first branch flow, performing simple character string matching on the logical text to obtain a logical index searching result, converting the logical index searching result into an original character index by using a preset index mapping relation for positioning, and executing simple replacement operation; if the fuzzy item list and the starting and stopping row index of the matching block are successfully matched, positioning is carried out by utilizing the index mapping relation, and fuzzy replacement operation of inserting the fuzzy item list into the placeholder is carried out; After the replacement operation is completed, the leading and trailing spaces of the text are restored. Further, the preset index mapping relationship is established by the following manner: establishing a bidirectional mapping dictionary between an original index and a logical index from which the head and tail space of each row is removed; The keys of the first mapping dictionary are character indexes of the original text, the values are corresponding indexes in the logical text, the keys of the second mapping dictionary are corresponding indexes in the logical text, and the values are character indexes of the original text. Further, the performing simple string matching in the first branch flow specifically includes: Obtaining a logical index searching range according to the original index searching range and the first mapping dictionary; and searching the logic searching content in the logic index searching range. Further, the performing the row-wise sliding comparison in the second branch flow specifically includes: analyzing each line of searching templates, and intelligently matching with the target line; And if all the lines of the multi-line searching content are successfully matched in sequence, recording the mu