V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
llhh
V2EX  ›  正则表达式

问个正则表达式的问题

  •  
  •   llhh · 2014-11-24 14:57:33 +08:00 · 1668 次点击
    这是一个创建于 3442 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想把下面的正则表达式浓缩下只有一个(.+?)。
    class="g">(.+?)</span>|<span class="c-showurl">(.+?)</span>

    匹配class="g">开头儿或者<span class="c-showurl">(.+?)开头,</span>结尾的字符串

    多谢。
    3 条回复    2014-11-24 16:57:40 +08:00
    imn1
        1
    imn1  
       2014-11-24 15:01:03 +08:00   ❤️ 1
    class="(?:g|c-showurl)">(.+?)</span>
    imn1
        2
    imn1  
       2014-11-24 15:04:02 +08:00   ❤️ 1
    class="(?:g|c-showurl)"[^>]*?>(.+?)</span>
    这样保险一点,因为不能确定class是最后一个属性
    xylophone21
        3
    xylophone21  
       2014-11-24 16:57:40 +08:00
    你想怎么处理
    <span class = "c-showurl">...<sth class="c-showurl">...</sth></span>
    ?

    纯正则角度
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2915 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:40 · PVG 15:40 · LAX 00:40 · JFK 03:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.