匹配表达式
我将提供一些常见情况下的匹配表达式的示例:
1. 正则表达式:
#匹配邮箱地址:
```regex
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
```
#匹配URL:
```regex
^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$
```
2. 字符串匹配:
#匹配字符串中是否包含特定单词:
```python
string = "Hello, World!"
word_to_match = "World"
if word_to_match in string:
    print("Match found!")
```
#判断字符串是否以特定前缀开头:
```python
string = "Hello, World!"
匹配邮箱的正则表达式
prefix_to_match = "Hello"
if string.startswith(prefix_to_match):
    print("Match found!")
```
#判断字符串是否以特定后缀结尾:
```python
string = "Hello, World!"
suffix_to_match = "World!"
dswith(suffix_to_match):
    print("Match found!")
```