varint
V2EX  ›  问与答

这条 PAC 规则何解?

  •  
  •   varint · Sep 21, 2015 · 2538 views
    This topic created in 3932 days ago, the information mentioned may be changed or developed.

    function FindProxyForURL(url, host) {
    if (/google/i.test(host)) return proxy;
    .......
    }

    5 replies    2015-09-22 00:27:04 +08:00
    varint
        1
    varint  
    OP
       Sep 21, 2015
    语法赶脚怪怪的。。。
    faceair
        2
    faceair  
       Sep 21, 2015
    如果 host 里面有 google 字样就直接代理
    varint
        3
    varint  
    OP
       Sep 21, 2015
    @faceair 用于其他网站,比如.cn ,把"google"替换成".cn"就可以么?
    varint
        4
    varint  
    OP
       Sep 21, 2015
    搜到了答案,自问自答一下:
    if(/google/i.test(host))拆开来写
    re = /google/i; 定义正则表达式用来匹配 google, i 表示不区分大小写
    if(re.test(host)) 判断 host 是不是匹配 google

    ref:
    http://bbs.csdn.net/topics/320061843
    Tink
        5
    Tink  
    PRO
       Sep 22, 2015
    还能这么写?万能的啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2728 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:16 · PVG 13:16 · LAX 22:16 · JFK 01:16
    ♥ Do have faith in what you're doing.