class RegexMatchTooMuch(Exception): pass
# set up pattern
pattern = re.compile(r'''
^["]* # text may or may not start with "
( # start defining group to return
[^"]* # the first character is not "
\. # next is .
csv # next is csv
) # end defining the group to return
["]*$ # text may or may not end in "
''', re.VERBOSE+re.IGNORECASE)
reres = pattern.findall('report for RIUD .csv')
if len(reres) == 1:
print(reres[0])
elif len(reres) == 0:
print('No match')
else:
raise RegexMatchTooMuch
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter