def first_10_matches(pattern): """ Return the first 10 story titles that match the provided regular expression """ all_matches = titles[titles.str.contains(pattern)] first_10 = all_matches.head(10) return first_10 pattern1 = r"\b[Cc]\b[^.+]" pattern2 = r"\b[Cc]\b[^+.]" first_10 = first_10_matches(pattern)
You can see the two patterns which follow different results. Can someone explain me the difference between them. I know that + is a special char that means 1 or more times of the previous char in regex. But I didn’t understand how the python algo runs it?
Why it works in pattern1 but not in pattern 2?