Python正则表达式:删除字符串末尾的模式

90a*_*yss 4 python regex

输入: blah.(2/2)

所需输出: blah

输入可以是“ blah。(n / n)”,其中n可以是任何一位数字。

如何使用正则表达式实现“等等”?这是我目前无法使用的正则表达式:

m = re.sub('[.[0-9] /\ [0-9]]{6}$', '', m)
Run Code Online (Sandbox Code Playgroud)

Pra*_*lan 5

您需要使用正则表达式 \.\(\d/\d\)$

>>> import re
>>> str = "blah.(2/2)"
>>> re.sub(r'\.\(\d/\d\)$', '',str)
'blah'
Run Code Online (Sandbox Code Playgroud)

正则表达式的解释在这里

正则表达式可视化