I have the following strings:
project_identifier = "CENTRAL PROPERTY DEVELOPMENTS JHB (PTY) LTD (1220681)"
plan_project_name = "BLP416223852-CENTRAL PROPERTY DEVELOPMENTS JHB (PTY) LTD"
acnac_Id = "BLP416223852"
project_sw_id = "1232831"
I am using the following regex to match plan_project_name string:pattern = rf"({acnac_Id}|{project_sw_id})(\s*-\s*)({project_name})"
spaces around the hyphen are allowed. I obtain the project name by striping the project_identifier string from the right as follows:
project_name = str((projectname.rsplit("(",1)[0]).rstrip())
then
match = re.match(pattern,plan_project_name)
I am failing to find the match even when using re.search
method, where am I getting it wrong?please help.
Part which you are missing are parentheses in project_name. You would have to escape them (and everything that could look like regex pattern. This code should work: