[英]Find and replace Heading tags with regex in Notepad++
有一本OCR扫描的书,还有一个将OCR的PDF转换成XML的工具,但是大多数XML标签是错误的,因此还有另一种工具可以修复它。 但是我需要从<h1>
到<h5>
,1.和1.1断开行。 &1.1.1。 因此使用该工具很容易重新标记。
XML代码如下所示:
`<h1>text</h1><h2>text</h3><h3>text</h3>"
和
1.text.2.text.3.text.1.1.text.1.1.1.text
而且我需要在记事本++中使用正则表达式来打破这样的界限。
<h1>text</h1>
<h2>text</h2>
<h3>text</h3>
和
1.text.
2.text.
3.text.
和
1.1.text.
1.1.1.text.
我使用</h1>\\s*
来找到</h1>\\n
但它只会破坏h1
标签。 我需要破坏所有的“ H”标签和1.,2.,1.1。,1.1.1。 标签。
冒着被低估的风险,我认为解析器可能会更好地为您服务。 过去,当我不得不管理类似的任务时,我会编写一个小的脚本/程序来解析文件并根据需要重新编写。 首先解析xml,然后使用正则表达式重新格式化可能更容易实现目标。
: 您可以使用此搜索并替换 :
search: (?<!^)(<h[1-6][^<]*|(?<![0-9]\.)[0-9]+\.)
replace: \n$1
注意:如果你需要使用Windows换行,必须更改\\n
与\\r\\n
。
图案细节:
(?<!^) # not preceded by the begining of the string
( # open the capture group 1
<h[1-6][^<]* # <h, a digit between 1 to 6, all characters until
# the next < (to skip all the content between
# h1, h2... tags)
| # OR
(?<![0-9]\.)[0-9]+\. # one or more digits and a dot not preceded by a digit
# and a dot
) # close the capture group 1
$1
是对捕获组1内容的引用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.