I want to check string which is not preceded by [a-zA-Z]
before attachment
.
def is_attachment_url(url):
"""check url"""
pattern = '(?<![\w]+)attachment'
return re.search(pattern, url, re.I)
tests = (
'article_?attachment', # should be false
'article_fattachment', # should be false
'article_-attachment', # should be true
'article_/attachment', # should be true
)
for ss in tests:
print(is_attachment_url(ss))
error tips:
raise error("look-behind requires fixed-width pattern")
sre_constants.error: look-behind requires fixed-width pattern