# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^\s*\K(?:^.*\S.*\r?\n)*?^.*[ ]चैव[ ]यत्[ ].*(?:\r?\n^.*\S.*)*"
test_str = ("सत्कारमानपूजार्थं तपो दम्भेन चैव यत् ।\n"
"क्रियते तदिह प्रोक्तं राजसं चलमध्रुवम् ॥ 17.18॥\n\n"
"दृष्ट्वा तु पाण्डवानीकं व्यूढं दुर्योधनस्तदा ।\n"
"आचार्यमुपसङ्गम्य राजा वचनमब्रवीत् ॥ १-२॥\n\n"
"पश्यैतां पाण्डुपुत्राणामाचार्य महतीं चमूम् ।\n"
"व्यूढां द्रुपदपुत्रेण तव शिष्येण धीमता ॥ १-३॥\n\n"
"अन्ये च बहवः शूरा मदर्थे त्यक्तजीविताः ।\n"
"नानाशस्त्रप्रहरणाः सर्वे युद्धविशारदाः ॥ १-९॥\n\n"
"अपर्याप्तं तदस्माकं बलं भीष्माभिरक्षितम् ।\n"
"पर्याप्तं त्विदमेतेषां बलं भीमाभिरक्षितम् ॥ १-१०॥\n\n\n"
"सत्कारमानपूजार्थं तपो दम्भेन चैव यत् ।\n"
"क्रियते तदिह प्रोक्तं राजसं चलमध्रुवम् ॥ 17.18॥\n"
"hello world\n\n"
" kk\n"
"kubhpkn\n"
"अभिसन्धाय तु फलं दम्भार्थमपि चैव यत् ।\n"
"इज्यते भरतश्रेष्ठ तं यज्ञं विद्धि राजसम् ॥ 17.12॥\n\n"
"अयनेषु च सर्वेषु यथाभागमवस्थिताः ।\n"
"भीष्ममेवाभिरक्षन्तु भवन्तः सर्व एव हि ॥ १-११॥\n\n"
" सत्कारमानपूजार्थं तपो दम्भेन चैव यत् ।\n"
" क्रियते तदिह प्रोक्तं राजसं चलमध्रुवम् ॥ 17.18॥\n\n"
"सत्कारमानपूजार्थं तपो दम्भेन चैव यत् ।\n"
"क्रियते तदिह प्रोक्तं राजसं चलमध्रुवम् ॥ 17.18॥")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html