weixin_33724059 2013-07-23 19:32 采纳率: 0%
浏览 23

javascript重定向和替换

<script type = "text/javascript">
    var r = window.location.href;
    if (r.match(/#|%23/)) {
        r = r.replace(/#|%23/gi, \"@NUM@\");
        window.location.href = r;
    }
</script>

This script will redirect the page and replace # symbols with @NUM@ in the URL (don't ask why)...

I'm trying to modify the script so it doesn't replace "#" if it is at the end of the URL

example:

http://www.example.com/test.php?f=abc#def

will become

http://www.example.com/test.php?f=abc@NUM@def

But this link:

http://www.example.com/test.php?f=abc#def#

will become:

http://www.example.com/test.php?f=abc@NUM@def#
  • 写回答

1条回答 默认 最新

  • weixin_33691598 2013-07-23 19:33
    关注

    Use a positive lookahead to guarantee that there is at least one more character:

    /(#|%23)(?=.)/g
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料