How do you capture and reuse Java regex match?

I am trying to remember the correct notation for performing find-replace regular expression matches in Java.

Say I have a line

String s = "My name is ''Eric'' and I have a bee called ''Eric'' and a fish called ''Wanda''." 

I want to do something like the following:

 s.replaceAll("\'\'$$\'\'", "$$"); 

To give: My name is Eric, and I have a bee called Eric and a fish called Wanda.

But I know that $$ is not the right notation to fix everything in '' and use it to replace the found match.

What specific notation am I looking for here?

Thanks in advance.

-Dave.

+8
java regex
May 19 '11 at 11:14
source share
1 answer
 s.replaceAll("\'\'(.*?)\'\'", "$1"); 
+6
May 19 '11 at 11:19
source share



All Articles