Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

222.Advanced search and replace -- How to handle conditional text replacement with 'if' and 'else' branches?

User: Renlin -- 2008-07-13          << 221  223 >>
Hits: 3445
Type: Advanced search and replace   
Search all Advanced search and replace examples
Description:
how to express with if? 
on multi-files, search for pattern is aaa.*?bbb|ccc.*?ddd (multi-lines), and "print unmatched units" is unchecked, Replac with pattern is $match. I want if text matches pattern, then return $match, else return all the original text. 
so how to express this with if? 
Input Sample:
a.txt 
 
12323 
.... 
dk 
kdf 
.... 
 
b.txt 
 
959 
... 
aaa 
... 
xxx xxx 
... 
bbb 
... 
38438 
 
c.txt 
 
957eii 
... 
ccc 
... 
xxx xxx 
.... 
ddd 
... 
215 jhj 4555555
Output Sample:
a.txt 
 
12323 
.... 
dk 
kdf 
.... 
 
b.txt 
 
aaa 
... 
xxx xxx 
... 
bbb 
 
c.txt 
 
ccc 
... 
xxx xxx 
.... 
ddd 
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
Sometimes 'Search for Pattern' can not handle some complicate situations, so we designed "IF" filter.  
If "IF" return 'True', the corresponding replace will happen, otherwise the replace will not happen. 
In one sentence, if can only decide "replace or not", can not decide "replace with this or that".  
 
Steps to resolve your issue: 
1. ctrl-o open your file 
2. ctrl-h open 'Replace' dialog 
 
* in 'Replace' page: 
 
set 'Search for pattern' to 
 
set 'Replace with pattern' to 
 
 
* select 'Advanced' page: 
 
set 'Run following for each matched unit' to: 
 
 
3. Click 'Replace', done!
Download Script:  scripts/222.rst.zip

Screenshot 1:  Replace_Window


Screenshot 2:  Replace_Advanced_Window


Similar Examples:
How to remove/delete all text between '1:' and 'user:'? (52%)
How to make multi-word replacement with a mapping list? (51%)
How to extract text from 'start' to 'end' in each line? (49%)
How to find the descriptions in text file and enclose them with a pair of tag? (47%)
How to remove all text between 'start' and 'end' for multiple files? (47%)
How to batch replace 'old' to 'new' in many pdf files? (47%)
How to batch replace 'old' to 'new' in many word doc files? (47%)
How to make multiple text replace at the same time? (47%)

Check Demo of Advanced search and replace
Keywords:
how to handle conditional text replacement with if and else branches  ddd  branch  conditional text replace  conditional text replacement  conditional  multifiles  condition  sig  text replacement  conditional replace text  conditional search replace text  conditional replacement text  conditional search and replace  conditional replace  search and replace sentence  replace sentence  replace original