[英]Regex to find and fix unmatched xml closing tags in notepad++
I'm trying to simplify the process of correcting missing unmatched verse
tags in an xml file that looks like this: 我正在尝试简化纠正如下所示的xml文件中缺少的不匹配
verse
标签的过程:
<verse number="21">words words words asdlkjf alsdf. </verse>
<verse number="22">words words words arbitrary words.
<verse number="23">more arbitrary text.</verse>
<verse number="23">other arbitrary words. </chapter>
I would like to use a regex in notepad++ to find the end of a line that starts with an arbitrary number of spaces and <verse
but does not end with </verse>
我想在notepad ++中使用正则表达式来查找以任意数量的空格和
<verse
但不以</verse>
结尾的行的结尾
With the end of the line matched, I should be able use notepad++ find/replace to add the missing tag back in. 在行尾匹配的情况下,我应该能够使用notepad ++查找/替换来添加丢失的标签。
Here is what I have so far, which matches every line (the whole line, unfortunately) that starts with spaces and <verse
这是我到目前为止的内容,它匹配以空格和
<verse
开始的每行(不幸的是,整行)
^( +<verse).*
Matching the end of the line is not possible, but you can match the whole line and put it back with the missing end tag: 不可能匹配行尾,但是您可以匹配整行并将其与缺少的end标签放回去:
Find: ^ *<verse>(.(?!</verse>))*(</\w*>)?$
Repl: $0</verse>$1
This could be what you look for: 这可能是您要寻找的:
Find: (^\\h+<verse(?!.*verse>\\h*).*?)((</.*?>\\h*)*)$
查找:
(^\\h+<verse(?!.*verse>\\h*).*?)((</.*?>\\h*)*)$
Replace: $1</verse>$2
替换:
$1</verse>$2
Given the sample data it will make two replacements, with this result: 给定样本数据,它将进行两次替换,结果是:
<verse number="21">words words words asdlkjf alsdf. </verse>
<verse number="22">words words words arbitrary words. </verse>
<verse number="23">more arbitrary text.</verse>
<verse number="23">other arbitrary words. </verse></chapter>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.