1

嗨,我有一个这样的字符串:

String s = "@Path(\"/BankDBRestService/customerExist(String")\";

我想将该字符串设为

@Path("/BankDBRestService/customerExist")

我试过这个:

String foo = s.replaceAll("[(](.*)", "");

我得到的输出为

@Path

谁能给我提供正则表达式来完成这项工作

4

2 回答 2

0

试试这个

    String foo = s.replaceAll("(.*)\\(.*\\)", "$1");
于 2013-09-11T06:52:16.557 回答
0

试试这个:

String s = "@Path(\"/BankDBRestService/customerExist(String\")";
String res = s.replaceAll("[(]([a-zA-Z_])+", "");
System.out.println(res);

输出 :@Path("/BankDBRestService/customerExist")

如果你的字符串是"@Path(\"/BankDBRestService/customerExist(String)\")"带有右括号的,那么使用正则表达式[(]([a-zA-Z_])+[)]

于 2013-09-11T06:52:43.793 回答