>>> import re
>>> match = re.search(r'PY.*N', 'PYANBNCNDN')
>>> match.group(0)
'PYANBNCNDN'
>>>
其中满足条件的有:
1. PYAN
2. PYANBN
3. PYANBNCN
4. PYANBNCNDN
结果输出了一个最长的:PYANBNCNDN
>>> import re
>>> match = re.search(r'PY.*N', 'PYANBNCNDN')
>>> match.group(0)
'PYANBNCNDN'
>>> match = re.search(r'PY.*N', 'PYANBNCND')
>>> match.group(0)
'PYANBNCN'
>>> match = re.search(r'PY.*N', 'PYABNCND')
>>> match.group(0)
'PYABNCN'
>>> match = re.search(r'PY.*N', 'PYABHDHDH')
>>>
最上面的那一个就是没有满足条件的!
match = re.search(r'PY.*?N', 'PYANBNCNDN')
>>> import re
>>> m = re.search(r'PY.*N', 'PYDFSNDFNJNCNIS')
>>> m.group(0)
'PYDFSNDFNJNCN'
>>> m = re.search(r'PY.*?N', 'PYDFSNDFNJNCNIS')
>>> m.group(0)
'PYDFSN'
>>>
课程地址:https://www.icourse163.org/learn/BIT-1001870001?tid=1003245012#/learn/content?type=detail&id=1004574448&cid=1005754054