में नई लाइन समेत है, मैं एक वेबसाइट से प्राप्त पाठ्यपुस्तक परिभाषाओं के लिए नियमित अभिव्यक्ति से मिलान करने की कोशिश कर रहा हूं। परिभाषा के बाद परिभाषा हमेशा एक नई पंक्ति के साथ शब्द है। उदाहरण के लिए:जावा रेगेक्स मैच
Zither
Definition: An instrument of music used in Austria and Germany It has from thirty to forty wires strung across a shallow sounding board which lies horizontally on a table before the performer who uses both hands in playing on it Not to be confounded with the old lute shaped cittern or cithern
मेरे प्रयास में बस मैं न्यू लाइन चरित्र बार आ रही है (इस मामले "जिट्रा" में) शब्द मिलता है।
मैंने बिना किसी किस्मत के ^(\w+)\s
और ^(\S+)\s
दोनों की कोशिश की। मैंने सोचा कि शायद ^(\S+)$
काम करेगा, लेकिन ऐसा लगता है कि यह शब्द सफलतापूर्वक मेल नहीं खाता है। मैं rubular, http://rubular.com/r/LPEHCnS0ri के साथ परीक्षण कर रहा हूँ; ऐसा लगता है कि जावा मेरे द्वारा किए जाने वाले तथ्य के बावजूद, मेरे सभी प्रयासों को सफलतापूर्वक मेल नहीं खाता है।
यहाँ मेरी टुकड़ा
String str = ...; //Here the string is assigned a word and definition taken from the internet like given in the example above.
Pattern rgx = Pattern.compile("^(\\S+)$");
Matcher mtch = rgx.matcher(str);
if (mtch.find()) {
String result = mtch.group();
terms.add(new SearchTerm(result, System.nanoTime()));
}
यह आसानी से जिसके परिणामस्वरूप स्ट्रिंग triming द्वारा हल किया जाता है, लेकिन वह जैसे कि यह अनावश्यक हो अगर मैं पहले से ही एक नियमित अभिव्यक्ति का उपयोग कर रहा चाहिए लगता है।
सभी मदद की बहुत सराहना की जाती है। अग्रिम में धन्यवाद!
'\ s' मैचों' \ n' दूसरों के बीच। –