0

I got a problem about Python Regex.

>>> import re
>>> print re.match('img', 'test.img')
None
>>> print re.match('test', 'test.img')
<_sre.SRE_Match object at 0x7f3fac8a0100>
>>>

Any character after dot(.) won't be parsed, is there any way to solve this problem?

1
  • 1
    I tend to play around with regexes for python here: pythonregex.com Commented Jun 19, 2014 at 13:31

1 Answer 1

7

re.match matches only at the beginning of the string. Use search instead. (See search() vs. match())

>>> import re
>>> re.match('img', 'test.img')
>>> re.search('img', 'test.img')
<_sre.SRE_Match object at 0x0000000002AB0100>
Sign up to request clarification or add additional context in comments.

Comments

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.