java - 在Java中使用正则表达式提取双引号之间的子字符串

标签 java regex

我有这样一个字符串:

"   @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/

相关文章:

java - 在哪里可以找到一些 Maven 生命周期文档

用于在 Linux 环境中构建类 chroot 路径的正则表达式

regex - SAS 正则表达式匹配 1-3 位数字

java - 服务器端 API 中的权限检查

java - 需要RESTLET + JAX-RS + JSON 好例子

java - 使用 Java SAX 解析缺少文档类型声明的 xhtml 的实体

python - 使用正则表达式从特定文本格式获取信息

javascript - 电子邮件验证正则表达式需要很长时间才能完成中等长度的字符串

Java,在正则表达式中转义(使用)引号

java - openGL 中的帧速率和绘制流程