# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\n(?=[^\"]+?\"\s*$)"
test_str = ("ability,n. 能力,能耐;才能\n"
"able,adj. 能; 有能力的;能干的\n"
"about,\"prep. 关于;大约\n"
"n. 大致;粗枝大叶;不拘小节的人\n"
"adj. 在附近的;四处走动的;在起作用的\n"
"adv. 大约;周围;到处\"\n"
"above,\"prep. 超过;在……上面;在……之上\n"
"n. 上文\n"
"adj. 上文的\n"
"adv. 在上面;在上文\"\n"
"accident,n. 事故;意外; 意外事件;机遇\n"
"accurate,adj. 精确的\n"
"ache,\"n. 疼痛\n"
"vi. 疼痛;渴望\"\n"
"activity,n. 活动;行动;活跃\n"
"actor,n. 男演员;行动者;作用物\n"
"actress,n. 女演员\n"
"actually,adv. 实际上;事实上")
subst = " "
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
# 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