开发者

How do you capture and reuse a match with Java regex?

开发者_如何学编程I'm trying to remember the correct notation for doing find-replace regex matches in Java.

Say I have the string

    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 $$ isn't the correct notation to capture whatever is in the '' and use it to replace the found match.

What's the particular notation I'm looking for here?

Thanks in advance.

-Dave.


s.replaceAll("\'\'(.*?)\'\'", "$1");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜