1

I have this pattern: "(\?(.+?))\b". In python, what should happen, is findall should return ("?var", "var") if i run it on the string: "some text ?var etc".

It works normally elsewhere, here's a regexr for proof.

In python, re's findall returns an empty list. Why is that?

2
  • 1
    I believe the re module documentation starts off by explaining how to solve your problem. Commented Apr 18, 2015 at 5:33
  • @user2357112 I feel pretty stupid sometimes. Commented Apr 18, 2015 at 5:40

1 Answer 1

2

You're not using raw string notation:

>>> import re
>>> re.findall(r'(\?(.+?))\b', 'some text ?var etc')
[('?var', 'var')]
Sign up to request clarification or add additional context in comments.

2 Comments

Yours works, but why does re.findall("(#{(.+?)})", "example #{findme}") work without raw string notation?
Because there are no escape sequences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.