में मैं निम्नलिखित कोड है:अजगर - प्रिंट स्ट्रिंग स्क्रीन करने के लिए, शामिल हैं N उत्पादन
pattern = "something.*\n" #intended to be a regular expression
fileString = some/path/to/file
numMatches = len(re.findall(pattern, fileString, 0))
print "Found ", numMatches, " matches to ", pattern, " in file."
मैं उपयोगकर्ता पैटर्न में शामिल देखने के लिए '\ n' सक्षम होना चाहते हैं। फिलहाल, पैटर्न में '\ n' स्क्रीन पर एक नई लाइन लिखता है। तो उत्पादन की तरह है:
Found 10 matches to something.*
in file.
और मैं इसे होना चाहते हैं:
Found 10 matches to something.*\n in file.
हाँ, pattern.replace ("\ n" "\ n") कार्य करता है। लेकिन मैं इसे \ t, \ e आदि सहित सभी प्रकार के बचने वाले पात्रों को मुद्रित करना चाहता हूं। किसी भी मदद की सराहना की जाती है। और मिलान के लिए एक प्रदर्शित करने के लिए एक -
displayPattern = "something.*\\n"
print "Found ", numMatches, " matches to ", displayPattern, " in file."
आप पैटर्न के प्रत्येक मामले के लिए एक अलग स्ट्रिंग निर्दिष्ट करना होगा:
यह पहले से ही कहा गया है इस बारे में हैं, उम्मीद है कि यह सही दिशा में बताते हैं: http://stackoverflow.com/questions/6477823/python-display-special-characters-when-using प्रिंट बयान – dkroy
'displayPattern =" कुछ। * \ s "' 'उपयोग \ s'' 'रेपर (स्ट्रिंग)' के बजाय न्यू लाइन चरित्र – abhishekgarg