Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I don't know how to perform a certain type of search and replace.

What I have tried:

To adapt an old source code within eclipse it will be very convenient to do a search and replace keeping one character of the original text and replacing it with a new text with the character in another position.

For example, find all the texts:

Text1sample, Text2sample, Text3sample

Ant replace them with:

newtext1ok, newtext2ok, newtext3ok.

I suspect that this is possible with Regular expressions, but being a total novice with them, I can find all the original texts but I cannot perform correctly the replacement. Anybody can help me, please?
Posted
Updated 17-Feb-23 3:16am
Comments
Andre Oosthuizen 17-Feb-23 8:44am    
for Python, Javascript, .Net etc? What code do you currently have? Where does the error occur? What is the error? We need more information to be able to assist.

1 solution

Try:
RegEx
([a-zA-Z]+)(?<number>\d+)([a-zA-Z]+)
And rthe replacement is:
RegEx
newtext${number}ok

If you are going to use regular expressions, you need a helper tool. Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900