原(https://baidu.com/aa/#/home?f...)
取到 /home 这些用/index替换
替换为(https://baidu.com/aa/#/index?...)
想替换掉/到?这一块
就是网址有可能是(https://baidu.com/aa/#/home?f...)
也可能是(https://baidu.com/aa/#/demo?f...)
用index把上面两个例子的home和index 这个位置的内容替换掉
var a = 'https://baidu.com/aa/'
a.replace(/\/home/, '/index')
是我的错觉吗, 还是有什么我没看懂的
var a = 'https://baidu.com/aa/'
a.replace(/#(.*?)\?/, '#/index?')
###
ok,理解了,修改了回答。
便于理解写成了python形式的,正则表达式在里边。
import re
a = "https://baidu.com/aa/#/home?f.."
b = re.search(r"(/[^/]*?)\?", a)
print(b.group(1))
# /home