Regular Expressions 101

Community Patterns

Last quoted string in text likely to be a filename

1

Regular Expression
PCRE (PHP <7.3)

/
(\"(?P<filename>[\p{L}\d\s\[\]_,.\-\(\)\+]+\.(?P<extension>\w{1,5}))\"(?!.*\"([\p{L}\d\s\.\[\]_,.\-\(\)\+]+\.\w{1,5})\"))
/

Description

When a string contains two or more possible filenames in quotes grab the last one and return it as <filename> and <extension>

Submitted by warlord - 8 years ago