【Python面试真题】- src = "security/afafsff/?ip=123.4.56.78&id=45",请写一段代码用正则匹配出IP ?
【Python面试真题】- src = "security/afafsff/?ip=123.4.56.78&id=45",请写一段代码用正则匹配出IP ?
import re
src = "security/afafsff/?ip=123.4.56.78&id=45"
m = re.search('ip=(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})', src, re.S) # re.S 改变'.'的行为
print m.group(1)
输出结果
123.4.56.78