我有一个像这样的字符串:
" @Test(groups = {G1}, description = "adc, def")"
Run Code Online (Sandbox Code Playgroud)
我想在Java中使用regexp提取"adc,def"(不带引号),我该怎么办?
Doo*_*nob 16
如果你真的想使用正则表达式:
Pattern p = Pattern.compile(".*\\\"(.*)\\\".*");
Matcher m = p.matcher("your \"string\" here");
System.out.println(m.group(1));
Run Code Online (Sandbox Code Playgroud)
说明:
.* - anything
\\\" - quote (escaped)
(.*) - anything (captured)
\\\" - another quote
.* - anything
Run Code Online (Sandbox Code Playgroud)
但是,不使用正则表达式要容易得多:
"your \"string\" here".split("\"")[1]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30574 次 |
| 最近记录: |