[英]Return the content of a Wildcard match in Python
是否可以在Python的正則表達式模式中返回與通配符(如。*)匹配的內容?
例如,匹配如下:
re.search('stack.*flow','stackoverflow')
將返回字符串“ over”。
使用捕獲組:
>>> import re
>>> re.search('stack(.*)flow', 'stackoverflow').group(1)
'over'
是的,您可以捕獲結果。 為此,只需使用()
matchobj = re.search('stack(.*)flow','stackoverflow')
print(matchobj.group(1)) # => over
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.