Notepad ++的正则表达式替换它?

时间:2023-01-17 23:36:53

This is an example of what I want to replace

这是我想要替换的一个例子

3</td><td width="8%">2

with

3 and 2

But the regex should match any number before the like the 3 above for the example, and the number 2 is always number 2

但是正则表达式应匹配任何数字,例如上面的3之前的数字,而数字2总是数字2

if you find a number before </td><td width="8%"> and the number 2 after it, you keep the numbers and replace </td><td width="8%"> with the word and

如果您在 之前找到一个数字,并且在它之后找到数字2,则保留数字并将 替换为单词和

Thank you

3 个解决方案

#1


1  

You can try to match with the following regex:

您可以尝试匹配以下正则表达式:

([0-9]+)</td><td\s*width="8%">2

and replace with the following:

并替换为以下内容:

$1 and 2

Look at the picture below:

看下图:

Notepad ++的正则表达式替换它?

#2


0  

I believe this should work:

我相信这应该有效:

[0-9]+</td><td\swidth="8%">2

If you editor supports groupped editing, use paranthesis to mark each group then edit the one you need.

如果编辑器支持分组编辑,请使用paranthesis标记每个组,然后编辑所需的组。

Groupped version:

([0-9]+)(</td><td\swidth="8%">)(2)

#3


0  

Capture the preceding number and output it back out in the replacement text using a back reference:

捕获前面的数字并使用后引用在替换文本中将其输出:

Search:

(\d+)</td><td width="8%">2

Replace:

\1 and 2

#1


1  

You can try to match with the following regex:

您可以尝试匹配以下正则表达式:

([0-9]+)</td><td\s*width="8%">2

and replace with the following:

并替换为以下内容:

$1 and 2

Look at the picture below:

看下图:

Notepad ++的正则表达式替换它?

#2


0  

I believe this should work:

我相信这应该有效:

[0-9]+</td><td\swidth="8%">2

If you editor supports groupped editing, use paranthesis to mark each group then edit the one you need.

如果编辑器支持分组编辑,请使用paranthesis标记每个组,然后编辑所需的组。

Groupped version:

([0-9]+)(</td><td\swidth="8%">)(2)

#3


0  

Capture the preceding number and output it back out in the replacement text using a back reference:

捕获前面的数字并使用后引用在替换文本中将其输出:

Search:

(\d+)</td><td width="8%">2

Replace:

\1 and 2