-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
  • 607,720
  • 39
  • 448
  • 563
PDHide
  • 18,113
  • 2
  • 31
  • 46

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
  • 3,238
  • 1
  • 20
  • 33