Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

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

原(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 这个位置的内容替换掉


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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?')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...