我有顯示課程編號,名稱,成績和學生所選課程的其他信息的文本。具體來說,線條看起來像這些:python re模塊 - 使用什麼正則表達式來提取文本片段
0301 453 20071 LINEAR SYSTEMS I A 4 4 16.0
0301 481 20071 ELECTRONICS I WITH LAB A 4 4 16.0
0301 481 20084 ELECTRONICS II WITH LAB RE B 4 4 12.0
0301 713 20091 SOLID STATE PHYSICS NG 0 0 0.0
0511 454 20074 INT'L TRADE & FINANCE B 4 4 12.0
我想寫一個正則表達式提取:
LINEAR SYSTEMS I
ELECTRONICS I WITH LAB
ELECTRONICS II WITH LAB
SOLID STATE PHYSICS
INT'L TRADE & FINANCE
我寫了下面
pattCourseName = re.compile(r'([-/&A-Z\':\s]{2,})(\s+[A-Z])')
然而,這給了我
LINEAR SYSTEMS I
ELECTRONICS I WITH LAB
ELECTRONICS II WITH LAB RE
SOLID STATE PHYSICS
INT'L TRADE & FINANCE
也就是說,我無法擺脫RE部分。
有人可以幫忙嗎?謝謝!
美麗的解決方案!謝謝! – Curious2learn 2010-10-24 13:25:58