V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
IP.IM 查询准确的IP地址信息
支持curl 提供全球IP超高准确度位置信息查询
Promoted by vsean
llhh
V2EX  ›  正则表达式

问个正则表达式的问题

  •  
  •   llhh · 2014-11-24 14:57:33 +08:00 · 1888 次点击
    这是一个创建于 3884 天前的主题,其中的信息可能已经有所发展或是发生改变。
    想把下面的正则表达式浓缩下只有一个(.+?)。
    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   ·   实用小工具   ·   999 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:03 · PVG 07:03 · LAX 16:03 · JFK 19:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.