PHP Regex Last Entry with Sperators
Sorry my regex skills are horrible. I am trying figure out how to just get the final entry in a text file i am manipulating. So the line of data is...
Paint & Maintenance///Cleaners, Soaps & Polishes///Vinyl Cleaners & Protectors
I need only the string of data that shows up after the last "///" (Vinyl Cleaners & Protectors) but the number of separators ("///") will vary each time.
Any Help is greatly app开发者_JAVA技巧reciated!
Don't need regex for that:
$delim = '///';
$str = 'Paint & Maintenance///Cleaners, Soaps & Polishes///Vinyl Cleaners / Protectors';
$str = substr($str, strrpos($str, $delim)+strlen($delim));
Edit:
Using native string functions is much faster than a regex expression. As a general rule, only use regex when absolutely necessary.
$last_item = array_pop(preg_split('|///|', $str));
(Edit: I think I misunderstood your statement about number of separators, adjusted.)
preg_match('/\/+(.+)$/',$in,$m); echo $m[1];
精彩评论