I have the following strings:
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:
import re
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:
project_name = re.escape(str((project_identifier.rsplit("(",1)[0]).rstrip()))
print(project_name)
pattern = rf"({acnac_Id}|{project_sw_id})(\s*-\s*)({project_name})"
print(pattern)
match = re.match(pattern,plan_project_name)
print(match)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.