php - Regular Expression String Break -
i new regex. have been trying break string initial part of string create folders.
here few examples of variables need break.
test1-792x612.jpg
test-with-multiple-hyphens-612x792.jpg
is there way using regular expression can test1
, test-with-multiple-hyphens
?
you can use regex this:
(.*?)-\d+x\d+
the idea pattern match string -numxnum
capture previous content. note case insensitive flag.
match 1 1. [0-5] `test1` match 2 1. [18-44] `test-with-multiple-hyphens`
if don't want use insensitive flag, change regex to:
(.*?)-\d+[xx]\d+
Comments
Post a Comment