【发布时间】:2013-03-24 14:51:21
【问题描述】:
我需要获取包含此文本的所有字符串 %variables% 这里有一些文字 %/variables%
例子
%enca% something here %variables% take this text %/variables%
other stuffs here, I dont need this
%variables% I need this too %/variables%
other stuffs, etc
我拥有的是这样的:
我试试这个:
%variables%(.*?)%/variables%
像这样工作(只有一场比赛)
但在 Java 中不起作用:
private boolean variablesTag(String s)
{
Pattern pattern = Pattern.compile("/%variables%(.*?)%/variables%/gs");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
//do some stuff...stored, work with the string, etc...
};
return true;
}
如果你能告诉我把绳子拿进去的方法,我真的很感激。 我想要的是这样的:
收下这段文字 这也是
我正在使用 NetBeans...
解决方案
Pattern pattern = Pattern.compile("%variables%(.*?)%/variables%",Pattern.MULTILINE|Pattern.DOTALL);
没有标志是行不通的
【问题讨论】: