import re
# 示例字符串
text = "Hello, welcome to the world of Python. HELLO is just the beginning."
# 匹配以 "hello" 开头的字符串,忽略大小写
pattern_start = re.compile(r'^hello', re.IGNORECASE)
result_start = pattern_start.search(text)
if result_start:
print("匹配到开头的字符串:", result_start.group())
else:
print("未匹配到开头的字符串")
# 匹配以 "beginning." 结尾的字符串,忽略大小写
pattern_end = re.compile(r'beginning.$', re.IGNORECASE)
result_end = pattern_end.search(text)
if result_end:
print("匹配到结尾的字符串:", result_end.group())
else:
print("未匹配到结尾的字符串")