I need to replace all words in a text by applying a specific replacement method Modify()
. I have the following code snippet in C#:
Regex regex = new Regex("[A-Za-z][a-z]*");
regex.Replace(text, x => Modify(x.Value));
The Modify()
function is some function that is executed to modify each match, for example it could replace all the characters in a word with the next alphabetical character. For example, if this is the input text:
Magic banana is eating the apple.
This could be the output:
Nbhjd cbobob jt fbujoh uif bqqmf.
The purpose of the Modify() function is irrelevant here. I am wondering about the Java implementation of the MatchEvaluator. The code is fairly simple in C#, but how would this be achieved in Java?