regex to replace string with params
问题 Please help me to create regex for replace a string like: /technic/k-700/?type=repair to a string like /repair/k-700/ Instead of k-700 can be any another combination (between / ) and instead of repair can be only kit . I need pattern and replacement, please. It's so hard for me. My result not working for Wordpress : $pattern = '/technic/([0-9a-zA-Z-]+)/?type=$matches[1]'; $replacement = '/?/([0-9a-z-]+)/'; 回答1: You can try something like this: $test = preg_replace( '~/\w+/([\w-]+)/\?type=(\w+