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'(
]*>Free
.*?30 minutes
.*?