# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[,\s]?([A-Za-z. '\s/()\"]+)?(Manager|manager)([A-Za-z. '\s/()]+)?(?=,)"
test_str = ("id,First Name,Last Name,Current Job1,Current Job2,PastJob1,PastJob2,PastJob3,Nan\n"
"0,Amanda,Maldonado,Recruiter,NA,Sales Associate,Waitress,Office Assistant,1\n"
"1,Ashley,Galetti,Project Manager,NA,Front of house manager,NA,NA,1\n"
"2,Brent ,Tally,President,NA,Director of Construction,NA,NA,1\n"
"3,Chris,Rodriguez,Sec/Treasure,Co-owner,NA,NA,NA,1\n"
"4,Corey,Miller,Top Ranked Multi-Unit Director,NA,Regional Director Services,Regional Installed Sales Director,Area Installation Manager,1\n"
"5,Cristian,Turcios,Project Assistant,NA,Contractor,NA,NA,1\n"
"6,David,Cone-Gorham,Owner,NA,\"Vice President, Regional Director\",Division Manager/ Executive Recuiter,NA,1\n"
"7,Devin,Rivers,Sr. Account Executive,NA,Full Desk Account Executive,NA,NA,1\n"
"8,Douglas W.,Fletcher,Deputy Construction Group Manager,NA,Construction Director,Operation Manager,Vice President of Construction,1\n"
"9,Dustin,Cox,Contracts Administrator,NA,Contracts / Operations Manager,Contract Administrator,Golden Contracts System Specialist,1\n"
"10,Eddie,Martinez,Vice President of Membership,Director of Safety and Risk,Construction manager,Assistant Project Manager,NA,1\n"
"11,Eric,Buckner,Sr. Construction Management Consultant,NA,\"Director, Project Operations\",\"Director, Construction Resource Management\",Project Manager/Site Manager,1\n"
"12,George,Dokos,Construction Recruiter,NA,President-Recruiter,Construction Recruiter,Construction Recruiter,1\n"
"13,Jay,Mogge,Co-Owner,Construction Manager,Senior Project Manager,Officer,NA,1\n"
"14,Jeff,Crenshaw,Construction Risk Management and advisor,NA,Sales,Scout Sniper Platoon Sergeant,Sales,1\n"
"15,Jeremy,Rainwater,Construction Field Manager,NA,Assistant Field Manager,General Manager,National Production Manager,1\n"
"16,Jim ,Conlow,General Contractor,NA,ReDevelopment Director,\"Division Manager, Energy Projects\",Construction; Development Management - President,1\n"
"17,Jimmy,Fong,Recruiter,NA,Production Specialist,Sales Representative,Specialist,1\n"
"18,Joe,Walton,Builder,Professional Home Inspector,Field Manager II,Construction Manager,NA,1\n"
"19,Keith,Eaton,Janitorial/Maintenance,NA,Project Manager,Project Manager/Engineer,Project Manager/Engineer,1\n"
"20,Kenneth,Dunn,T&D Outage Planner,NA,Construction Manager,Project Manager,Superintendent,1\n"
"21,Lauren,Stafford,Senior Sales Manager,Sales Manager,Sales Support Coordinator,Builder relations,Customer Experience Lead,1\n"
"22,Mike,Seery,President,President,Project Manager,Managing Partner,NA,1\n"
"23,Paul,Horn,Sales Estimator,NA,Territory Sales Manager,Territory Sales Manager,National Account Manager,1\n"
"24,Paul,Pollesch,Design and Construction Services Manager,NA,Assistant Operations and Maintenance Officer,MSCE Graduate Student,Company commander/ Assistant Operations Officer,1\n"
"25,Paul ,Hooks,Vice president of Construction Management,NA,Project Manager,Project Manager/Interiors Division Manager,NA,1\n"
"26,Ray ,LaMonica,\"Project Controls, Engineering, Construction Management Recruiter\",Account Recruiting Manager,Territory Sales Executive,Business Account Executive,NA,1\n"
"27,Ray ,Meyer,Vice President,Adjunct Professor/Construction Management,NA,NA,NA,1\n"
"28,Roy ,Flournoy,Superintendent,NA,Project Manager,Superintendent,Superintendent,1\n"
"29,Roy ,Allen,Owner,NA,Construction Project management & Project superintendent,Construction Project Manager and Project Superintendent,Construction Project Manager and Project Superintendent,1\n"
"30,Ryan,Salladay,Senior Recruiter,NA,Sales Executive,Associate Vice President of Sales,Fitness professional,1\n"
"31,Sam,ller,Principal,NA,Director of Safety Services,Director of Field Safety Operations,Owner,1\n"
"32,Steven,Hadley,President,Construction Management Alumni,Director of Program Management,Estimator,Realtor,1\n"
"33,Stewart,Scott,Project Executive,NA,\"Vice President of Engineering, Program Management\",\"Corporate Vice President Capital Projects, Property Management\",Senior Project Manager,1\n"
"34,Suadad,Al tameemi,Construction Inspector,NA,Quality Inspector,Planning Manager and Supervising Engineer,\"Scheduler, Supervisor Engineer\",1\n"
"35,Tony,Pacifico,Senior Project Manager,NA,Senior Project Manager,Construction Management Consultant,Senior Project Manager,1\n"
"36,Truitt,Rounsavall,Project Manager,NA,Facilities Manager (Contract),Program Manager,Project Manager,1\n"
"37,Virgil,Gray,Vice president of Construction Management,NA,Manager of Construction Services,\"Principal Consultant, Program Management Office (PMO)\",Vice President,1\n"
"38,Zach,Kempthorne,Project Management Consultant,NA,Project superintendent,Project Superintendent,Project Manager/Operations Manager,1\n")
subst = ",3"
# 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