可移动类型:使用regex replace删除URL的一部分
我想用我在下面尝试过的regex_replace删除部分uf url,但它不能正常工作。我正在尝试删除“index1.php” 代码输入:可移动类型:使用regex replace删除URL的一部分,regex,movabletype,Regex,Movabletype,我想用我在下面尝试过的regex_replace删除部分uf url,但它不能正常工作。我正在尝试删除“index1.php” 代码输入: http://www.myblog.com/blog/content/fruit/index1.php 我的代码 <mt:getvar name="permalink" regex_replace="/index1\.(php)$/",""> 但应该是这样 http://www.myblog.com/blog/content/fruit/
http://www.myblog.com/blog/content/fruit/index1.php
我的代码
<mt:getvar name="permalink" regex_replace="/index1\.(php)$/","">
但应该是这样
http://www.myblog.com/blog/content/fruit/
尝试以下模式:
<mt:getvar name="permalink" regex_replace="/\/[^\/]+$\/","">
或者,尝试使用捕获组:
<mt:getvar name="permalink" regex_replace="/(.*\/)index1[.]php$\/","$1">
对于您发布的示例,您不需要使用
regex\u replace
,只需使用:
现在还不清楚您是否计划使用
regex\u replace
来实际执行正则表达式匹配(可能数字有所不同或其他),但如果不是,则replace更容易、更快。您的代码输出是什么?你为什么不使用这个regex_replace=“/index1\.php$/”,“
@AvinashRaj输出应该是”“我还编辑了页面以使其更有意义。@AvinashRaj我犯了一个错误输出是你说的“我正在尝试删除”index1.php”“是的,我想删除index1.php部分
<mt:getvar name="permalink" regex_replace="/(.*\/)index1[.]php$\/","$1">
<mt:GetVar name="permalink" replace="index1.php","">