我有这样一个字符串:
" @Test(groups = {G1}, description = "adc, def")"
我想在 Java 中使用正则表达式提取“adc, def”(不带引号),我应该怎么做?
最佳答案
如果你真的想使用正则表达式:
Pattern p = Pattern.compile(".*\\\"(.*)\\\".*");
Matcher m = p.matcher("your \"string\" here");
System.out.println(m.group(1));
解释:
.* - anything
\\\" - quote (escaped)
(.*) - anything (captured)
\\\" - another quote
.* - anything
但是,不使用正则表达式要容易得多:
"your \"string\" here".split("\"")[1]
关于java - 在Java中使用正则表达式提取双引号之间的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14574689/