如何在字符串中输入括号内的值 [英] How can i get inside parentheses value in a string
本文介绍了如何在字符串中输入括号内的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在字符串中输入括号内的值。
How can i get inside parentheses value in a string.
String str= "United Arab Emirates Dirham (AED)";
我只需要AED文本。谢谢
I need only AED text. Thanks
推荐答案
编译并打印AED。甚至适用于多个括号:
Compiles and prints "AED". Even works for multiple parenthesis:
import java.util.regex.*;
public class Main
{
public static void main (String[] args)
{
String example = "United Arab Emirates Dirham (AED)";
Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(example);
while(m.find()) {
System.out.println(m.group(1));
}
}
}
正则表达式意味着:
-
\\(
:字符(
-
(
:start match group -
[
:其中一个字符 -
^
:不是以下字符 -
)
:使用之前的^
,这意味着除了之外的每个字符
-
+
:来自[]的其中一项内容
设置 -
)
:停止匹配组 -
\\)
:文字闭幕式
\\(
: character(
(
: start match group[
: one of these characters^
: not the following character)
: with the previous^
, this means "every character except)
"+
: one of more of the stuff from the[]
set)
: stop match group\\)
: literal closing paranthesis
这篇关于如何在字符串中输入括号内的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文