पर काम नहीं कर रहा है मेरे पास लाइन और शुरुआत के संकेत को इंगित करने के लिए^और $ का उपयोग करके एक पैटर्न है।
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 में संघर्ष किया है - खुद भी जावाडोक में ब्योरा दफनाया जाता है; सारांश एक संक्षिप्त स्पष्टीकरण का उपयोग कर सकता है। मैंने वर्षों से इस कई बार सामना किया है, हल किया है, और भूल गया है। अगली बार यह stackoverflow सवाल होगा! –