How to match if every occurrence of . or + is happening at the end of the string

Hello community!
I would like some help regarding my solution to the exercise.

pattern = r"(?<!Series\s)((?<!\w)[Cc](?!\w))(?=.+$)" 

In the last term I want my pattern to match if every occurrence of . or + is happening at the end of the
string. However my results don’t encapsulate that and I cannot understand why this is the case.

To my understanding (?=.+$) states the following:

Accept whatever is preceding if the following sub-string is equal to either the characters . or + which if they are found at the end of the string.

Thank you very much in advance.
Giannis

Hello,

I’m no regex expert, but I’ll try to help.

If you want to select the + character, then you should use \ to scape it. The + is a special character that means you want to match one or more of the preceding character, in this case ..

Try it like this: (?=.\+$).

I also suggest you take a look at https://regexr.com/. This will help you to test the regex you’re writing.

I hope this helps you.

1 Like

Thanks you very much for the pointers and your help sir!

1 Like

Since the idea is to exclude either “+” or “.”, you must indicate in your forward looking statement. (?![\.\+])