# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\b\S+\b)(?=.*\b\1\b)"
test_str = ("123-1 123-2 test-1 test-1 w/e 10/04/20\n"
"Company w/e 09/06/20 083020-090620\n"
"a/b 01/01\n"
"test_1 test_2\n"
"a/b a/b\n"
"Inv 50049 50049 Inv 50195 PrjPAN02\n"
"Inv 51360-1, 51366-7; 51372 Inv 51360-1, 51366-7; 372 PrjPAN02\n"
"Inv 51360-1, 51366-7; 51372 51372 Inv 513601, 51366-7; 372 PrjPAN02\n"
"55009, 55017, 55022 55001, 55022, 55025\n"
"55254, 61 55246,66,69\n"
"55733, 41, 44 55727, 45,48\n"
"57269, 71,74,75, 57354 57266, 73\n"
"57437, 38, 41, 43 57434, 40\n"
"w/e 09/20/20 091320-092020")
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