Please tell me how to use the regular expression for the string:

re-medbedb-re-darksun-re-bit8k-khorosho-li-chto-kazhdyi-den-sozdayutsya-novye-kriptovalyuty-20161102t054454811z 

cut out all the substrings starting with re-, and the date from the end of the line, leaving only the middle? The number of substrings with re is an unknown number.

In this case, I want to get this at the output:

 khorosho-li-chto-kazhdyi-den-sozdayutsya-novye-kriptovalyuty 

I understand that it is possible to be confused with recursive sub_str, but some garbage. Regular expression will turn out beautifully, but .. there for me the most complete dark forest so far - I myself can not figure it out in a week.

 $re = '/^.+-re-.+?-(.+)-\d+.+/m'; $str = 're-medbedb-re-darksun-re-bit8k-re-dfsfdf-khorosho-li-chto-kazhdyi-den-sozdayutsya-novye-kriptovalyuty-20161102t054454811z re-medbedb-re-darksun-re-bit8k-dsdsdsd-li-chto-kazhdyi-den-sozdayutsya-novye-kriptovalyuty-20161102t054454811z '; preg_match_all($re, $str, $matches); // Print the entire match result print_r($matches); 
  • Isn't it what you needed in the $ matches [1] element? - Visman

1 answer 1

 preg_replace("/re-[^-]*-/","",$str);