简体   繁体   English

正则表达式Notepad ++替换

[英]Regular Expression Notepad++ replace

I'm trying to replace only the 'remove' strings in this block of code: 我正在尝试仅替换此代码块中的“删除”字符串:

<table asldkjf>
remove
remove
remove
<tr>

The problem is keeping the 'asldkjf' string within the table tag. 问题是将'asldkjf'字符串保留在表标记内。

I've tried replacing 我尝试更换

<table[^>]*>[^<]*<tr>

with

<table[^>]*><tr>

And I got 我得到了

<table[^>]*><tr>

Which is incorrect as it replaced the 'asldkjf' with '[^>]*' 这是不正确的,因为它将'asldkjf'替换为'[^>] *'

I've tried replacing based on reference 我已经尝试根据参考进行替换

<table[^>]*>[^<]*<tr>

with

<table$1><tr>

And I got 我得到了

<table><tr>

Which is also incorrect. 这也是不正确的。

Use capturing group and surround the pattern, whose text you want to use in the replacement. 使用捕获组并围绕模式,您要在替换中使用其文本。 You can refer to them with $n , where n is the number of the capturing group. 您可以使用$n引用它们,其中n是捕获组的编号。

For more information about how capturing group works, look at this answer . 有关捕获组如何工作的更多信息,请查看此答案

Find what: 找什么:

(<table[^>]*>)[^<]*(<tr>)

Replace with: 用。。。来代替:

$1$2

You can use this reegx 您可以使用此reegx

(?<=<table asldkjf>).*(?=<tr>)

and replace with empty string. 并替换为空字符串。 Use dotall modifier. 使用dotall修饰符。

DEMO DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM