简体   繁体   中英

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.

I've tried replacing

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

with

<table[^>]*><tr>

And I got

<table[^>]*><tr>

Which is incorrect as it replaced the 'asldkjf' with '[^>]*'

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.

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

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

and replace with empty string. Use dotall modifier.

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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