Python match '.\' at start of string

Viewed 180

I need to identify where some powershell path strings cross over into Python.

How do I detect if a path in Python starts with .\ ??

Here's an example:

import re

file_path = ".\reports\dsReports"

if re.match(r'.\\', file_path):
    print "Pass"
else:
    print "Fail"

This Fails, in the debugger it lists

  expression = .\\\\\\
   string = .\\reports\\\\dsReports

If I try using replace like so:

import re

file_path = ".\reports\dsReports"
testThis = file_path.replace(r'\', '&jkl$ff88')

if re.match(r'.&jkl$ff88', file_path):
    print "Pass"
else:
    print "Fail"

the testThis variable ends up like this:

testThis = '.\\reports&jkl$ff88dsReports'

Quite agravating.

1 Answers
Related