import re with open('home_content.html', 'r', encoding='utf-8') as f: content = f.read() # Replace all "Schedule an initial assessment" links pattern1 = r'(]*href=")([^"]+)("[^>]*>\s*Schedule an initial assessment\s*)' content = re.sub(pattern1, r'\g<1>https://calendly.com/ktmckeand/coaching-assessment\g<3>', content, flags=re.IGNORECASE) # Replace the "Book Now" link specifically for Initial Assessment block_pattern = r'(]*>Initial Assessment.*?]*>Free

.*?

30 minutes

.*?
.*?]*href=")([^"]+)("[^>]*>Book Now)' content = re.sub(block_pattern, r'\g<1>https://calendly.com/ktmckeand/coaching-assessment\g<3>', content, flags=re.DOTALL) with open('home_content_updated.html', 'w', encoding='utf-8') as f: f.write(content)