V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
upufo
V2EX  ›  问与答

javascript 的正则表达式 不支持优先取分组里面的值 有什么解决办法吗

  •  
  •   upufo · 2016-03-21 07:36:46 +08:00 · 1351 次点击
    这是一个创建于 2966 天前的主题,其中的信息可能已经有所发展或是发生改变。
    正则: hello src=(.+) yes
    内容: hhsdj dskj hello src=value yes

    上面的正则只能匹配出 [ hello src=value yes ]
    如果我想要取等号后面的 value 这个字符串 应该怎么写呢?
    2 条回复    2016-03-21 09:07:30 +08:00
    TTry
        1
    TTry  
       2016-03-21 08:03:42 +08:00   ❤️ 1
    str.match(regexp)[1]
    ppgs8903
        2
    ppgs8903  
       2016-03-21 09:07:30 +08:00   ❤️ 1
    var re = /hello src=(.+) yes/;
    var str = "hhsdj dskj hello src=value yes";
    re.exec(str);
    alert(RegExp.$1);
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2391 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 11:37 · PVG 19:37 · LAX 04:37 · JFK 07:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.