0

Java正規表現を使用しています。次のような文字列があります

String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}";

上記の文字列に対してs.replaceAll( "\\{(.*?)\\}", "" )、次の文字列を返します。

the location is at with the name ,

これを逆にして、次の結果を取得します。

{emp.address.street}{emp.name}{emp.surname}

4

2 に答える 2

1

このテスト済みのスクリプトは私のために機能します:

public class TEST
{
    public static void main( String[] args )
    {
        String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}";
        String result = s.replaceAll( "[^{}]+|(\\{(.*?)\\})", "$1" );
        System.out.println(result);
    }
}
于 2011-10-11T03:34:58.967 に答える
0

を作成し、Patternを使用Matcher.find()Matcher.group()て、そのパターンの一部を取得できます。クラスの Javadoc は次のとおりです。Matcher javadoc Pattern javadoc

于 2011-10-11T03:27:31.647 に答える