I wrote a function that verifies if a specific pattern exists in a given string:
import re
def has_pattern(string, regex):
if string and re.compile(regex).search(string) is not None:
return True
return False
but for some reason my test doesn't show the expected result:
# for absolute path on windows
pattern = '^[a-zA-Z]:\\\\[^\\\\]' # actual regex: [a-zA-Z]:\\[^\\]
path = 'a:\\' # for this result should be 'True'
print('Pattern: \'{0}\''.format(pattern))
print('Result: {0}'.format(has_pattern(path, pattern)))