在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java  Python/ Python 正則 提取小括號以及小括號里面的內(nèi)容

Python 正則 提取小括號以及小括號里面的內(nèi)容

例如一個字符串:'American(United States of)'
要提取出:'(United States of)'
又或者'Abcde(Df WD asdAS ASDW)'
提取出:'(Df WD asdAS ASDW)'
要用正則表達式的方式
謝謝各位大佬了

回答
編輯回答
話寡
import re

s = 'American(United States of)'

r = re.search('(\(.*?\))', s)
if r:
    print(r.group())
2017年7月25日 05:42
編輯回答
咕嚕嚕
import re
In [26]: re.findall(r'.*(\(.*\)).*', 'American(United States of)')
Out[26]: ['(United States of)']

In [31]: m = re.match(r'.*(\(.*\)).*', 'American(United States of)')

In [32]: if m:
    ...:     print(m.groups())
    ...:     
('(United States of)',)
2017年1月8日 03:32