1
我的正则表达式今天很弱。我试图将字符串中的组分成5个部分,格式为:正则表达式分组
substring delimiter substring number(space) substring
我试过使用字边界但没有成功。 。我已经诉诸使用*(贪婪和懒惰,我知道)这是比所有
这里没有工作更好一点就是我有:
import re
s = "FOREVER - Alabaster Cuttlefish - 01 This Style Is Cheese"
m = re.compile("(.*)(\s-\s)(\d{1,3}\s)(.*)")
g = m.match(s)
if g:
print m.match(s).group(1) # FOREVER
print m.match(s).group(2) # -
print m.match(s).group(3) # Alabaster Cuttlefish
print m.match(s).group(4) # 01
# fail
# print m.match(s).group(5) # This Style Is Cheese
5组不存在,因为它得到在第一组中捕获。因此我的困惑。