将具有行号的xml标记添加到每行

时间:2019-03-04 15:27:04

标签: xml notepad++

我有一个包含500行文本的文本文件。我需要将xml标记添加到每一行。 例如,我需要转换

sentence 
another sentence
another sentence

<line id="x1">sentence</line>
<line id="x2">another sentence</line>
<line id="x3">another sentence</line>

我在Automatically wrap custom XML tags and numbering them上尝试了解决方案 但只会将标签编号到第9行() 我尝试将find中的术语从([0-9] +)\ s +(。)更改为([0-999] +)\ s +(。)和([000-999] + )\ s +(。*),无论我如何尝试,我都无法通过第九行

1 个答案:

答案 0 :(得分:0)

该链接的说明对我有用,但是,它只能转到9的原因是因为在9之后,使用“列编辑器”添加数字后,这些行看起来像这样:

1 sentence 
2 another sentence
3 another sentence
4 another sentence
5 another sentence
6 another sentence
7 another sentence
8 another sentence
9 another sentence
10another sentence // note no space after 9 here!
11another sentence
12another sentence
13another sentence
14another sentence
15another sentence

因此,要做的第一件事是使用列编辑器,使用Text to Insert选项,在每行的开头添加一个空格。 (确保光标位于第1行的开头)

然后,在添加空格之后,再次使用“列编辑器”将数字添加到每行。 (同样,请确保光标位于第1行的开头) 使用Number to Insert选项(将Initial number设置为1,Increase by设置为1),以便对所有行进行编号,并且外观应与此类似:

1  sentence 
2  another sentence
3  another sentence
4  another sentence
5  another sentence
6  another sentence
7  another sentence
8  another sentence
9  another sentence
10 another sentence
11 another sentence
12 another sentence
13 another sentence
14 another sentence
15 another sentence

完成这两个步骤后,请使用您应该可以使用的链接中的正则表达式。请注意,对链接中的替换正则表达式进行了稍微修改,以添加带有您要包含的ID的x
<line id='x$1'>$2</line>

格式化并使用指向上面几行的稍作修改的替换正则表达式后,这就是最终的输出:

<line id='x1'>sentence </line>
<line id='x2'>another sentence</line>
<line id='x3'>another sentence</line>
<line id='x4'>another sentence</line>
<line id='x5'>another sentence</line>
<line id='x6'>another sentence</line>
<line id='x7'>another sentence</line>
<line id='x8'>another sentence</line>
<line id='x9'>another sentence</line>
<line id='x10'>another sentence</line>
<line id='x11'>another sentence</line>
<line id='x12'>another sentence</line>
<line id='x13'>another sentence</line>
<line id='x14'>another sentence</line>
<line id='x15'>another sentence</line>