#!/usr/bin/python
import re
regex = re.compile('B', re.IGNORECASE)
print regex.match('abc')
Run Code Online (Sandbox Code Playgroud)
当它匹配时返回None.我正在尝试使用正则表达式'B'和搜索字符串'abc'与忽略大小写
re.match()尝试从输入字符串的开头匹配.
看来你想re.search(),它会扫描输入字符串寻找匹配.
import re
regex = re.compile('B', re.IGNORECASE)
m = regex.search('abc')
if m:
print m.group(0)
Run Code Online (Sandbox Code Playgroud)
输出:
b
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
774 次 |
| 最近记录: |