How to match a variable list of items separated by commas
Posted
by user261915
on Stack Overflow
See other posts from Stack Overflow
or by user261915
Published on 2010-04-06T17:19:50Z
Indexed on
2010/04/06
17:23 UTC
Read the original article
Hit count: 148
I want to turn something like this
CS 240, CS 246, ECE 222, ... (more or less); Software Engineering students only
into
('CS 240', 'CS 246', 'ECE 222', 'ECE 220')
in Python, code that matches a single course looks like
>>> re.search('([A-Z]{2,5} \d{3})', 'SE 112').groups()
('SE 112',)
I prefer a regular expression only method because I have a bunch of other alternate reg exps using '|' to combine them. However, a method with split is acceptable.
© Stack Overflow or respective owner