varint
V2EX  ›  问与答

这条 PAC 规则何解?

  •  
  •   varint · Sep 21, 2015 · 2768 views
    This topic created in 4080 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
    varint
    OP
    Sep 21, 2015
    1
    语法赶脚怪怪的。。。
    faceair
    faceair
    Sep 21, 2015
    2
    如果 host 里面有 google 字样就直接代理
    varint
    varint
    OP
    Sep 21, 2015
    3
    @faceair 用于其他网站,比如.cn ,把"google"替换成".cn"就可以么?
    varint
    varint
    OP
    Sep 21, 2015
    4
    搜到了答案,自问自答一下:
    if(/google/i.test(host))拆开来写
    re = /google/i; 定义正则表达式用来匹配 google, i 表示不区分大小写
    if(re.test(host)) 判断 host 是不是匹配 google

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