我有一个字符串,其中有两个单引号,'
个字符.在单引号之间是我想要的数据.
如何编写正则表达式从以下文本中提取"我想要的数据"?
mydata = "some string with 'the data i want' inside";
我有一个字符串,其中有两个单引号,'
个字符.在单引号之间是我想要的数据.
如何编写正则表达式从以下文本中提取"我想要的数据"?
mydata = "some string with 'the data i want' inside";
假设需要单引号之间的部分,请将此正则表达式与Matcher
:
"'(.*?)'"
示例:
String mydata = "some string with 'the data i want' inside";
Pattern pattern = Pattern.compile("'(.*?)'");
Matcher matcher = pattern.matcher(mydata);
if (matcher.find())
{
System.out.println(matcher.group(1));
}
结果:
the data i want