7
^と$を使用して行の先頭と末尾を示すパターンがあります。このような
Pattern pattern = Pattern.compile("^Key2 = (.+)$");
と入力:
String text = "Key1 = Twas brillig, and the slithy toves"
+ "\nKey2 = Did gyre and gimble in the wabe."
+ "\nKey3 = All mimsy were the borogroves."
+ "\nKey4 = And the mome raths outgrabe.";
しかしpattern.matcher(text).find()
戻りfalse
。
この機能はありませんか? Pattern class documentationでは、概要が指定されています。
Boundary matchers ^ The beginning of a line $ The end of a line
素晴らしい:)私は過去 – AbtPst
@AbtPstに自分自身これで苦労しています - 私自身も。 javadocの詳細は埋まっています。要約は簡単な説明を使用することができます。私はこれを何年もかけて何度も遭遇し、解決し、忘れてしまった。次回は、このstackoverflowの質問があります! –