看板 Python 關於我們 聯絡資訊
: p = re.compile(r'\]\s(.*?);|\]\s(.*)') ^^^^^ ^^^^ RE 中用小括號括起來的會進 Capturing group。 這是根據小括號出現的位置決定的,所以你寫了2個小括號,自然就有 2 筆資料 : [("School 1", ""), ("", "School 2") : 請問該怎麼解決這個問題呢? 最簡易的方法就是跑一遍 List 把空資料拿掉。 如果用 split 的話可以試試︰ re.split(r";?\s*\[[^\]]*\]\s*|\s+", s) -- (* ̄▽ ̄)/‧★*"`'*-.,_,.-*'`"*-.,_☆,.-*` http://i.imgur.com/oAd97.png
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.226.132.104 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1427685595.A.CAA.html
hohiyan: 感謝!我來研究一下! 03/30 12:06