How can I get inside parentheses value in a string?

前端 未结 10 726
半阙折子戏
半阙折子戏 2020-12-23 13:35

How can I get inside parentheses value in a string?

String str= "United Arab Emirates Dirham (AED)";

I need only AED text.

10条回答
  •  北海茫月
    2020-12-23 14:37

    Using regular expression:

    String text = "United Arab Emirates Dirham (AED)";
    Pattern pattern = Pattern.compile(".* \\(([A-Z]+)\\)");
    Matcher matcher = pattern.matcher(text);
    if (matcher.matches()) {
        System.out.println("found: " + matcher.group(1));
    }
    

提交回复
热议问题