改行の直後に式を一致させたいと思います。私はgnu.regexpとフラグREG_MULTILINEを使用しています。 Here's私は複数行gnu正規表現
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;
ありがとう、これは私を助けました。 /r/nが正しく機能しています。 – AlfonsSocken