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+ 

working demo

enter image description here

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

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -