我有一个字符串:
some text here 'quoted text here' some more text
我想在没有引号的情况下获取'引用文字'。除了使用indexOf(')然后使用substring之外,我怎样才能在Java中使用正则表达式来查找它?
答案 0 :(得分:2)
String text = "some text here 'quoted text here' some more text";
String regex = "'(.*?)'";
Pattern pattern = Pattern.compile(regex);
Matcher m = pattern.matcher(text);
if (m.find()){
String s = m.group(1);
System.out.println(s);
}