我有一些输入数据,例如
some string with 'hello' inside 'and inside'
如何编写正则表达式,以便返回引用的文本(无论重复多少次)(所有出现的情况)。
我有一个返回单引号的代码,但我想让它返回多次出现:
String mydata = "some string with 'hello' inside 'and inside'";
Pattern pattern = Pattern.compile("'(.*?)+'");
Matcher matcher = pattern.matcher(mydata);
while (matcher.find())
{
System.out.println(matcher.group());
}
最佳答案
查找我所有的事件:
String mydata = "some '' string with 'hello' inside 'and inside'";
Pattern pattern = Pattern.compile("'[^']*'");
Matcher matcher = pattern.matcher(mydata);
while(matcher.find())
{
System.out.println(matcher.group());
}
输出:
'' 'hello' 'and inside'
模式描述:
' // start quoting text [^'] // all characters not single quote * // 0 or infinite count of not quote characters ' // end quote
关于java - 用于匹配引号内模式的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14833012/