Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

245.Advanced search and replace -- How to replace the last occurance of some text like 'abc' to 'def' in a text file?

User: editor -- 2008-08-09
Hits: 238
Type: Advanced search and replace   
Search all Advanced search and replace examples
Description:
How to replace the last occurance of some text like 'abc' to 'def' in a text file?
Input Sample:
first occurance of abc
second occurance of abc
other text
last occurance of abc
other text
Output Sample:
first occurance of abc
second occurance of abc
other text
last occurance of def
other text
Answer:
Hint: You need to Download and install "Replace Pioneer" to finish following steps.
1. ctrl-o open text file
2. ctrl-h open 'Replace' dialog
set "Search for pattern" to:

set "Replace with Pattern" to:

3. click 'Replace', done!

Note: .*?abc will match from beginning to first 'abc', .*abc will match from beginning to last 'abc'.
chars($match,1,-4) means keep from 1st to -4th characters(remove last 3 chars:abc)
Download Script:  scripts/245.rst.zip

Similar Examples:
How to replace the last occurance of 'old' in every line with 'new'? (67%)
How to count the occurrance of specific pattern in each line of text file? (58%)
How to replace every 3 instances found in a text file? (58%)
How to delete the first word in each line in a text file? (58%)
How to remove the first 10 characters of each line in text file? (57%)
How to batch replace the last 5 "old" with "new" in a text file? (57%)
How to replace text containing some special symbols like /!@#$%^&*()'"~` in a text file? (57%)
How to reverse the order of all the lines in a text file? (56%)

Check Demo of Advanced search and replace