Here is what I've tried so far:
/(?:\/(en(\?|$)|fa(\?|$)))|\?/
输入
http://localhost:8000/search/fa?q=sth
http://localhost:8000/search?q=sth
http://localhost:8000/search
http://localhost:8000/search/fa
预期输出:
http://localhost:8000/search/en?q=sth
http://localhost:8000/search/en?q=sth
http://localhost:8000/search/en
http://localhost:8000/search/en
如您所见,我需要匹配?
,但不要选择它。另外,我需要在第三个网址末尾添加/en
。
如何修复模式?