#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from re import sub

i = '8.0.4.211111GW.87bb0b4'
print(sub("\D", '', i))

通过\D把非数字元素替换成空即可得到一串纯数字

执行效果


Administrator@DESKTOP-AI8CT25 MINGW64 /e/BaiduNetdiskWorkspace/Code/xc/check (master)
$ cat t.py
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from re import sub

i = '8.0.4.211111GW.87bb0b4'
print(sub("\D", '', i))

Administrator@DESKTOP-AI8CT25 MINGW64 /e/BaiduNetdiskWorkspace/Code/xc/check (master)
$ python t.py
8042111118704

Administrator@DESKTOP-AI8CT25 MINGW64 /e/BaiduNetdiskWorkspace/Code/xc/check (master)
$