Why is each line captured as a group except for the last one?

While I have your attention, do you have any idea why the following doesn’t work in regex101?

Q9:
r"(.+)\s(.+)"

8/4/2016 11:52
1/26/2016 19:30
6/23/2016 22:20
6/17/2016 0:01
9/30/2015 4:12

It captures each line as a group with the exception of the last line.

When I change it to:
r"(.+) (.+)"
It works just fine.

I changed it to Python. Is there something else I’m missing?

Can you save the regex and share the saved regex? I’m unable to reproduce this.

I didn’t realise at first that the data in your post came from the lesson. There is a huge difference between the lesson and what you’re doing on regex101.

In regex101, you’re running the regular expression engine over one string (that happens to have multiple lines), while in the content, through pandas, the regex engine is only looking at each line individually. To do an equivalent thing to what is done in the content, test one line at a time.

The above now helps explain what it works as you expect with a space, but not as you expect with \s. I think it’s helpful for you to figure it out on your own. Let me know if you have trouble with this and me or someone else will explain it.

1 Like