【发布时间】:2012-02-03 07:01:44
【问题描述】:
我想在新行之后匹配一个表达式。我正在使用 gnu.regexp 和标志 REG_MULTILINE。 这是我要检查的字符串
Hello
Dude
我的方法是使用这个正则表达式来匹配。
String strRegExp = "^[Dd][Uu][Dd]";
但它不起作用。看不出问题出在哪里。 我在一个简单的单元测试中运行所有这些:
@Test
public void testREMatchAtStartOfNewLine()
throws Exception {
String strRegExp = "^[Dd][Uu][Dd]";
int flags = RE.REG_MULTILINE;
String strText ="Hello\nDude";
RE re = new RE(strRegExp, flags, RESyntax.RE_SYNTAX_PERL5);
REMatch match = re.getMatch (strText);
String strResult = "";
if (match != null) {
strResult = match.substituteInto ("$0");
}
assertEquals("Match at start of new line ", "Dud", strResult); // FAILS
}
提前致谢。 编辑: 为了澄清,我正在使用以下导入:
import gnu.regexp.RE;
import gnu.regexp.REMatch;
import gnu.regexp.RESyntax;
【问题讨论】: