Php 在正则表达式中包含文本字符串

Php 在正则表达式中包含文本字符串,php,regex,.htaccess,Php,Regex,.htaccess,当前URL: http://domain.com/index.php?route=common/home http://domain.com/index.php?route=account/register http://domain.com/index.php?route=checkout/cart http://domain.com/index.php?route=checkout/checkout 所需URL: http://domain.com/home http://domain.c

当前URL:

http://domain.com/index.php?route=common/home
http://domain.com/index.php?route=account/register
http://domain.com/index.php?route=checkout/cart
http://domain.com/index.php?route=checkout/checkout
所需URL:

http://domain.com/home
http://domain.com/register
http://domain.com/cart
http://domain.com/checkout
正则表达式:

(?=\=)(.*?)(?<=\/).+$

(?=\=)(.*?(要移除所需零件,应替换:

index.php\?route\=[^\/]*\/
使用空字符串。 为了更加严格和准确,您应该使用lookback:

(?<=http:\/\/domain.com\/)index.php\?route\=[^\/]*\/

(?要移除所需零件,应替换:

index.php\?route\=[^\/]*\/
使用空字符串。 为了更加严格和准确,您应该使用lookback:

(?<=http:\/\/domain.com\/)index.php\?route\=[^\/]*\/

(?你到底想做什么?不清楚。我的正则表达式从
=
匹配到
(包括两个字符),我需要在匹配中包括
index.php?route
,这样我就可以替换整个字符串,使新的URL看起来像
domain.com/home
index.php\?route=[a-z]*\/$
-一个非常好的工具。@Eldo.Ob
在RegExr上没有匹配的
,但是很好的工具!@3zzy哦,是的,只需删除
index.php\?route=[a-z]*\/
结尾处的“$”?你到底想做什么?不清楚。我的正则表达式匹配从
=
(包括两个字符),我需要在匹配中包括
index.php?route
,以便替换整个字符串,使新URL看起来像
domain.com/home
index.php\?route=[a-z]*\/$
-一个非常好的工具。@Eldo.Ob
在RegExr上没有匹配的
,但是很好的工具!@3zzy哦,是的,只需删除
index.php\?route=[a-z]*\/
@3zzy我不知道RegExr.com是否可以使用php语法或其他任何东西。@3zzy我不知道RegExr.com是否可以使用php语法或其他任何东西。