{"id":52,"date":"2013-03-19T18:44:53","date_gmt":"2013-03-19T18:44:53","guid":{"rendered":"http:\/\/ecodebook.wordpress.com\/?p=52"},"modified":"2013-03-19T18:44:53","modified_gmt":"2013-03-19T18:44:53","slug":"php-regex-remove-everything-after-last-slash-including-last-slash","status":"publish","type":"post","link":"https:\/\/blog.mycarts.shop\/?p=52","title":{"rendered":"PHP: Regex remove everything after last slash &amp; including last slash"},"content":{"rendered":"<h4>Remove everything after last slash<\/h4>\n<p>[code language=&#8221;php&#8221;]<br \/>\n$string = &#8216;AAA\/BBB\/CCC&#8217;;<br \/>\necho preg_replace(&#8216;#[^\/]*$#&#8217;, &#8221;, $string);<br \/>\n[\/code]<\/p>\n<p><strong>Output: AAA\/BBB\/<\/strong><\/p>\n<h4>Remove everything after last slash including last slash<\/h4>\n<p>[code language=&#8221;php&#8221;]<br \/>\n$string = &#8216;AAA\/BBB\/CCC&#8217;;<br \/>\necho preg_replace(&#8216;#\\\/[^\/]*$#&#8217;, &#8221;, $string);<br \/>\n[\/code]<\/p>\n<p><strong>Output: AAA\/BBB<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Remove everything after last slash [code language=&#8221;php&#8221;] $string = &#8216;AAA\/BBB\/CCC&#8217;; echo preg_replace(&#8216;#[^\/]*$#&#8217;, &#8221;, $string); [\/code] Output: AAA\/BBB\/ Remove everything after last slash including last slash [code language=&#8221;php&#8221;] $string = &#8216;AAA\/BBB\/CCC&#8217;; echo preg_replace(&#8216;#\\\/[^\/]*$#&#8217;, &#8221;, $string); [\/code] Output: AAA\/BBB<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":0,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mycarts.shop\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}