-3

i wanted to match all the dates matching 31\05\2017

i tried :

b=re.compile(r'31\05\2017')
b=re.compile('31\05\2017')
b=re.compile('31\\05\\2017')
b=re.compile(r'31\\05\\2017')

and what ever pattern i use , the below code gives same result

c=b.search('31\05\2017')
print(c.group())

gives '31\x05\x817'

how to get 31\05\2017

instead of null and other character being print

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
PDHide
  • 15,234
  • 2
  • 19
  • 35

1 Answers1

3

The input to b.search actually consists of '31', a special character '\05', a special character '\201', and the digit '7'. You need to use a raw string literal for that too:

>>> re.compile(r'31\\05\\2017').match(r'31\05\2017')
<_sre.SRE_Match object; span=(0, 10), match='31\\05\\2017'>
tiwo
  • 2,916
  • 1
  • 19
  • 31