Mam wzorek, używając^i $, aby wskazać początek i koniec linii.
Pattern pattern = Pattern.compile("^Key2 = (.+)$");
i wejście tak:
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.";
Ale pattern.matcher(text).find()
powraca false
.
Czy to nie działa? W Pattern class documentation, podsumowanie określa:
Boundary matchers ^ The beginning of a line $ The end of a line
fantastyczna :) I zmagali się z tym w ubiegłym – AbtPst
@AbtPst - Ja również. Szczegóły w javadoc są pochowane; streszczenie może posłużyć się krótkim wyjaśnieniem. Napotkałem, rozwiązałem i zapomniałem to wiele razy przez te wszystkie lata. Następnym razem będzie to pytanie stackoverflow! –