请正则大佬,替换一段url:(https://baidu.com/aa/#/home?flag=bb)

阅读 2.6k
2 个回答
var a = 'https://baidu.com/aa/#/home?flag=bb'

a.replace(/\/home/, '/index')

是我的错觉吗, 还是有什么我没看懂的


var a = 'https://baidu.com/aa/#/home?flag=bb'

a.replace(/#(.*?)\?/, '#/index?')

ok,理解了,修改了回答。
便于理解写成了python形式的,正则表达式在里边。

import re

a = "https://baidu.com/aa/#/home?f.."

b = re.search(r"(/[^/]*?)\?", a)

print(b.group(1))
# /home
推荐问题