# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r".+(?=(?:AN|N)-\d+)|(?<=(?:AN|N)-\d+)\s.+"
test_str = ("2 BILLING ID AN-19 RPS Ex : “00411850177 “\n"
"3 FILLER AN-11 RPS EX: “ “\n"
"4 FILLER AN-15 RPS EX: “ “\n"
"5 FILLER AN-30 RPS EX: “ “\n"
"6 FILLER AN-2 RPS EX: “ “\n"
"7 FILLER AN-1 RPS EX: “ “\n"
"8 BILLER CODE AN-4 RPS Ex : “1310” 1302 means PDAM Mitracom\n"
"9 FILLER AN-11 RPS EX: “ “\n"
"10 ADMIN FEE N-12 LPZ Ex : “000000075000”\n"
" 11 FILLER AN-11 RPS EX: “ “\n"
"12 FILLER AN-12 RPS EX: “ “ ")
subst = ""
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0)
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