Hi
Could you please help me in a regex problem?
I have a regex pattern in a string. I want to apply this on a text, and wherever it is applied the matched text should be replaced by the length of the found text. Now I have done it with a while loop, but it takes too long to process:
Pattern p = Pattern.compile(patternString);
Matcher m = p.matcher(text);
// I dont know how to get this job done with m.replaceAll(). Thats why the following loop
// By the way, in Perl there is "eval" with which we can do this
while (m.find()) {
String foundText = m.group();
Pattern p2 = Pattern.compile( Pattern.quote(foundText) );
text = p2.matcher(text).replaceAll( foundText.length() );
}
Is there a better way? Kindly help.
Thanks
Sri