Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

906.Regular expression replace -- How to search and replace text for specified occurrences with reg exp?

User: editor -- 2012-01-25          << 905  907 >>
Hits: 55
Type: Regular expression replace   
Search all Regular expression replace examples
Description:
How to search and replace text for specified number of occurrences(times) using
regular expression? For example, I want to search the first 3 numbers(with regular expression \d+), and multiply them by 2.
Input Sample:
the first number is 10, the second
number is 20, the third is 30, the
fourth is 40
Output Sample:
the first number is 20, the second
number is 40, the third is 60, the
fourth is 40
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
With Replace Pioneer, you can use 'unit number filter' to 
control how many occurrences you want to search and replace 
a string, even if you are using a regular expression.
1. ctrl-o open text file
2. ctrl-h open 'replace' dialogue
* set 'search for pattern' to the text you want to search:

* set 'unit number filter' to the occurrences you want to 
search(5..10 means 5,6,7,8,9,10):

* set 'replace with pattern' to the text you want to 
replace(you can use function here!):

3. click 'replace', done.
4. ctrl-s save to file.

Screenshot 1:  Replace_Window


Similar Examples:
How to search and replace words in specified column in csv file? (69%)
How to search and replace text 'ReplaceMe' only in specified lines? (68%)
How to replace one specified word with a sequence of words from a file? (61%)
How to search and replace with multiple mapping rules by regular expression? (60%)
How to batch extract specified lines from a text file? (59%)
How to insert a line after specific lines in a text file? (58%)
How can I search and replace multiple strings in multiple files all at once? (56%)
How to search and replace in multiple files base on user-defined mapping file? (56%)

Check Demo of Regular expression replace
Keywords:
101  control  multiply  even  unit number filter  number filter  replace a string  a string  string  function  regular expression example replace how to  multiply file  replace first string  text pattern filter  replace with pattern regular expression  filter number  how to replace a string  replace example