开发者

PHP Regex Last Entry with Sperators

开发者 https://www.devze.com 2023-02-22 22:09 出处:网络
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...

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号