# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"((concorde|immo )?invest\b(\sconseil)?|investi(e?s)?$|sans invest.+)"
test_str = ("NE PAS PRENDRE EN COMPTE\n"
"concorde invest\n"
"invest conseil\n"
"pro immo invest\n"
"avons investi\n"
"très investies\n"
"nous sommes investis\n"
"sans investissement suplémentaire\n\n"
"pattern = ((concorde|immo )?invest\\b(\\sconseil)?|investi(e?s)?$|sans invest.+)\n"
"---------------------------------------------------------------\n"
"pattern = (investi[a-z]+|invest )\n\n"
"idéal invest\n"
"ideal premier investissement\n"
"ideal occupant et investisseur\n"
"idéal pour investir\n"
"projet pour investisseurs\n"
"pour faire un investissement\n"
"idéal pour investissement\n"
"local pour investissement\n"
"local commercial pour investisseur\n"
"parfait pour des investisseurs\n"
"idéal investisseur\n"
"idéal pour utilisateur ou investisseur\n"
"idéal profession libérale ou investisseur\n\n"
"s’adressant à des investisseurs\n"
"dédié à l'investissement\n"
"vente destinée à investisseurs\n"
"a vendre investissement\n"
"à vendre dans le cadre d'un investissement\n\n"
"des activités comme investisseur\n\n"
"bel investissement\n"
"excellent investissement\n\n"
"opportunité investisseur\n"
"opportunité d'implantation ou d'investissement\n"
"opportunité pour investir\n"
"opportunité à l'investissement\n\n"
"exclusivité investisseur\n"
"exclusivité vente a investisseur\n"
"spécial investisseurs\n\n"
"rentabilité pour investissement\n"
"investissement à forte rentabilité\n"
"produit investissement\n\n"
"rentabilité 8% pour investisseurs\n"
"investissement sans risque\n"
"investir en toute sécurité\n\n"
"investissement idéal\n\n"
"soyez les premiers à investir\n\n"
"disponible à la vente en investissement\n"
"vente de murs occupés à investisseur\n\n"
"investir sur ces murs libres\n\n"
"propose à la l'investissement\n\n"
"conviendrait à un investisseur\n\n")
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