I am using the Python 3.5
'\\\\192.168.1.2\\shared\\Department\\Travel\\FY 2015\\Travel Expense Statement Jul 25 2019.pdf'
Department\Travel\FY 2015\Travel Expense Statement Jul 25 2019.pdf
sre_constants.error: nothing to repeat at position 12
x=re.compile( "shared\\[^\\](*?)" )
print( x.findall(test) )
x=re.compile( "shared\\\(.*?)" )
The problem with your regular expression is very simple, remove the
? character in your second regular expression. You just need
.* that matches zero or more characters.
*? together means a lazy quantifier that matches as little as possible, so if you use
.*?, it means "zero or more any characters, but as few as possible". As for the first regular expression, the
* does not have a preceding atom to which it could apply to, hence the error.
In general case, you should rather use the
ntpath module as in kennytm's answer there.