# Task 7: Matches a word containing 'z' Write a Python program that matches a word containing 'z', not at the start or end of the word. Sample data : "The quick brown fox jumps over the lazy dog." "Python Exercises." Expected Output : Found a match! Not matched!
时间: 2024-01-10 12:03:07 浏览: 81
python开发Word助手的程序.7z
Here is a Python program that matches a word containing 'z', not at the start or end of the word:
```python
import re
# Sample data
text1 = "The quick brown fox jumps over the lazy dog."
text2 = "Python Exercises."
# Define the regular expression pattern
pattern = r'\b\w*z\w*\b'
# Test the regular expression on the sample data
match1 = re.search(pattern, text1)
match2 = re.search(pattern, text2)
# Print the output based on the match result
if match1:
print("Found a match!")
else:
print("Not matched!")
if match2:
print("Found a match!")
else:
print("Not matched!")
```
Output:
```
Found a match!
Not matched!
```
阅读全文