【发布时间】:2011-03-12 15:52:47
【问题描述】:
我是使用模式的新手,我在互联网上到处寻找这个问题的解释。
假设我有一个字符串:String info = "Data I need to extract is 'here' and 'also here'";
我将如何提取单词:
here
also here
没有使用单引号的模式?
这就是我目前所拥有的......
Pattern p = Pattern.compile("(?<=\').*(?=\')");
但它返回(here and 'also here)减去括号,这只是为了查看。它跳过了第二条数据,直接跳到最后一个引用...
谢谢!
编辑:
谢谢大家的回复!怎么可能改变模式,以便 here 存储在 matcher.group(1) 中,而 also here 存储在 matcher.group(2) 中?我出于不同的原因需要这些值,将它们从 1 组中拆分出来似乎效率低下...
【问题讨论】: