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          << 244  246 >>
Hits: 449
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" on windows platform 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)

** For newer version, you can search "(.*)abc" and replace with "\1def"
Download Script:  scripts/245.rst.zip

Screenshot 1:  Replace_Window


Similar Examples:
How to replace the last occurance of 'old' in every line with 'new'? (67%)
How to replace each xxx with the first word in the same line in text file? (61%)
How to count the occurrence of a list of words in a text file? (60%)
How to replace text containing some special symbols in a text file? (59%)
How to count and sort the occurrence of different numbers in a text file? (58%)
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%)

Check Demo of Advanced search and replace
Keywords:
occurance  1st  abc  toc  remove last  keep  last  beginning  las  ran  replace first occurance  replace abc def  keep first  replace first last  replace abc  replace last  first match  search and replace first