Regular Expressions 101

Community Patterns

Windows file path regex with root, relative path, and (image) file extension matching.

0

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?P<Root>[A-Za-z]:(?:\/|\\))(?P<Relative>(?:(?:[^<>:"\/\\|?*\n])+(?:\/|\\))+)(?P<File>(?:[^<>:"\/\\|?*\n]+)(?:\.(?:png|jpg|jpeg)))$
/
gm

Description

If u want to change the file extension match, just replace : (?:png|jpg|jpeg) by anything u want. Example : (?:txt|pdf) or (?:mp3|ogg) or (?:mp4) or etc...

Submitted by Holome - a year ago