使用正则表达式从Java中的圆括号内提取字符串 [英] Extracting string from within round brackets in Java with regex
本文介绍了使用正则表达式从Java中的圆括号内提取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从圆括号中提取字符串。
假设我有 John Doe(123456789)
我希望输出字符串 123456789
仅限。
I'm trying to extract a string from round brackets.
Let's say, I have John Doe (123456789)
and I want to output the string 123456789
only.
我找到了此链接和此正则表达式:
I have found this link and this regex:
/\(([^)]+)\)/g
但是,我无法弄清楚如何获得想要的结果。
However, I wasn't able to figure out how to get the wanted result.
任何帮助将不胜感激。谢谢!
Any help would be appreciated. Thanks!
推荐答案
String str="John Doe (123456789)";
System.out.println(str.substring(str.indexOf("(")+1,str.indexOf(")")));
这里我正在执行字符串操作。我对正则表达式并不熟悉。
Here I'm performing string operations. I'm not that much familiar with regex.
这篇关于使用正则表达式从Java中的圆括号内提取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文