简体   繁体   中英

Notepad++ Regex Find and Replace

I have sample data file with following format data

Data_Set = "001" , Status = "TRUE" ;
Data_Set = "002" , Status = "TRUE" ;
Data_Set = "003" , Status = "TRUE" ;
Data_Set = "004" , Status = "TRUE" ;
Data_Set = "005" , Status = "TRUE" ;
Data_Set = "006" , Status = "TRUE" ;

and I want replace all above data as below format

RMV_Set = "001" , Status = "TRUE" ; (mistake)

Corrected, required output

RMV_Set = "001" , Status = "001" ;
RMV_Set = "002" , Status = "002" ;
RMV_Set = "003" , Status = "003" ;
RMV_Set = "004" , Status = "004" ;
RMV_Set  = "005" , Status = "005" ;
RMV_Set = "006" , Status = "006" ;

I have tried following Regex method in Notepad++ and it won't work, please help me solve this

**Find** : Data_Set = "[0-9]*" , Status = "TRUE" ;
**Replace** : RMV_Set = "$1" , Status = "TRUE" ;

Just replace Data_Set with RMV_Set why you need regex for this?

If you want to replace every occurrence of Data_ in your file

You can avoid using a RegEx and just:

Find Data_

Replace RMV_

If you need to make sure to only replace in the right context

You can use this RegEx: Data_Set?=?("\d+")(?=?, ?Status?=?"TRUE"?;)

  • Data_Set?=? matches Data_Set = literally with or without spaces

  • ("\d+") captures one or more digits surrounded by ""

  • (?=?, ?Status?=?"TRUE"?;) (?=... ) makes sure the following expression is found after your match.

Find Data_Set?=?("\d+")(?=?, ?Status?=?"TRUE"?;)

Replace RMV_Set = $1

Demo.

Also try my solution as well

Find what: data(_.*")(\d+")(.*")true"
Replace with: RMV$1$2$3$2

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