This is not for homework!
Hello,
Just a quick question about Regex formatting.
I have a list of different courses.
L = ['CI101', 'CS164', 'ENGL101', 'I-', 'III-', 'MATH116', 'PSY101']
I was looking for a format to find all the words that start with I, or II, or III. Here is what I did. (I used python fyi)
for course in L:
if re.search("(I?II?III?)*", course):
L.pop()
I learned that ? in regex means optional. So I was thinking of making I, II, and III optional and * to include whatever follows. However, it seems like it is not working as I intended. What would be a better working format?
Thanks
re.match('^I{1,3}.*$'), please see regex101.com/r/HDS4TX/1.pop()operation will always remove the first element in the list. Consider using a list comprehension like so:[ c for c in courses if re.match("^I{1,3}.*", c) ]